All Questions
Tagged with concurrency scala
609
questions
0
votes
0
answers
18
views
Multiple streamed response combined in a single iterator in Scala
I have multiple replicas of a service from which I am receiving a stream of response:
// RPC call to server that returns a stream of response.
def getResult(input: Request): Iterator[ResultItem]
On ...
0
votes
0
answers
51
views
Postgres, implement optimistic lock
I have multiple service instances, they compete for job execution. My goals
a job must be assigned to one of service instances.
service can't run more than 2 jobs at a time
Here is my SQL query:
...
1
vote
0
answers
59
views
implementing mapAsync in scala
I'm trying to implement a mapAsync method for general sequences. Somehow it works when used independently, but it doesn't work when used inside a flatMap. Example code
import akka.actor.ActorSystem
...
1
vote
1
answer
272
views
Scala Akka Quickstart: Java Version Mismatch and Compilation Error
I am relatively new to Scala and Akka, transitioning from a Java, Spring, and REST API background. Currently, I am working through the Akka Actors Quickstart with Scala tutorial.
Upon attempting to ...
0
votes
1
answer
50
views
Creating an empty Scala Future to be completed externally
Is it possible / how to create an empty Future, set the necessary callbacks for its completion, and then set its result at a different point in time? In pseudocode (uncompilable) that would look like ...
1
vote
2
answers
455
views
When to use scala.concurrent.blocking?
I am asking myself the question: "When should you use scala.concurrent.blocking?"
If I understood correctly, the blocking {} only makes sense to be used in conjunction with the ForkJoinPool. ...
0
votes
2
answers
188
views
How to demonstrate thread safety issue
A coworker told me this Cache object needs to be made thread-safe:
import scala.collection.mutable
object Cache {
private val data = mutable.Map[Int, String]()
def get(key: Int): Option[...
0
votes
1
answer
240
views
Scala: Prevent race condition when performing some action after one Future fails out of a sequence of futures
I have a mutable list of futures: ArrayBuffer[Future[Seq[T]]]
While my program is running, new Futures are added to that list over time, and complete on their own eventually. After each Future ...
1
vote
1
answer
179
views
Scala thread safety
I'm running this code in Scala:
def injectFunction(body: =>Unit): Thread = {
val t = new Thread {
override def run() = body
}
t
}
private var counter: Int = 0
def ...
-1
votes
1
answer
57
views
Why does my code not return query results?
Creating the database works. SQLite editor returns correct values. Yet, running below code does not return results. I added println("completed") to verify this part of code is reached:
val ...
-2
votes
1
answer
56
views
I am doing asynchronous processing with scala, but it is not displayed
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
def now() = new java.util.Date();
(1 to 30).foreach(_ => Future{Thread.sleep(2000);println(now)})
I am ...
2
votes
1
answer
145
views
Using Scala groupBy(), from method fetchUniqueCodesForARootCode(). I want to get a map from rootCodes to lists of uniqueCodes
I want to to return Future[Map[String, List[String]]] from fetchUniqueCodesForARootCode method
import scala.concurrent._
import ExecutionContext.Implicits.global
case class DiagnosisCode(...
1
vote
1
answer
49
views
Return Future[List[DiagnosisCode]] from fetchDiagnosisForUniqueCodes method
I am not able to return Future[List[DiagnosisCode]] from fetchDiagnosisForUniqueCodes
import scala.concurrent._
import ExecutionContext.Implicits.global
case class DiagnosisCode(rootCode: String, ...
0
votes
0
answers
47
views
Cleaning the resources in case of failure after applying Future.sequence
Suppose we have a class which allocates some resources on the heap, and creating it takes some time, so it's hidden behind the future
class Container(val n: Int) {
allocateMemoryOnTheHeap(n)
def ...
0
votes
0
answers
189
views
How to fire N Requests per Second in Scala
I am developing an application in Scala, which is kind of request processor in batch. It gets the required data from storage and forms the request and calls an API of another service (named ServiceB)
...