Reputation: 635
In Scala singletons are created using Object classes and when serval Akka actors call methods in particular Object, would race condition occur ?
Upvotes: 0
Views: 304
Reputation: 17933
Agree with, S V's answer. A convenient "guard" for values is to use Agent
. Reads are immediate, writes are asynchronous:
import scala.concurrent.ExecutionContext.Implicits.global
import akka.agent.Agent
val agent = Agent(5)
Future {agent send 12}
Future { agent send (_ + 4)}
Future { agent send (_ * 2)}
Upvotes: 1
Reputation: 580
If the object holds state, then yes. It will require proper synchronization guards
Upvotes: 5