akka - What is the correct way to implement Producer Consumer in scala -
I try to apply a Producer Consumer Program in Scala without any queue. Because I think the actor has already implemented "mail queue" or something else, it would be useless to write the code again.
I tried to write the program purely in Actor. Below is a multiple manufacturer multiple consumer programs. The manufacturer sleeps a little while to do something that the consumer does not slept at all.
However, I do not know how to close the program if I do not add supervisor to the actor to monitor the consumers, as well as using the "wait" (supervisor) class in the promise code)
Do not have any way to get rid of them? There is a problem in the function creator class that it will not be closed because it is time to break the situation. The only way I can think of the "send the message to the creator himself" I wonder if this is the usual way of applying this type of request? There is a modified code here: Regardless of my implementation, what is the correct way to implement the manufacturer consumer program in the scales with the actor or the future / promise ? Instead, use a
class creator (val pool: actorf) (val name: string) Extension of the actor [// Basic implementation: // DRF = {// case _ = & gt; // while (true) {// val sleepTime = scala.util.Random.nextInt (1000) // thread Sleep (sleep time) // println ("Manufacturer sends food" format name) // pool! Name {}}} Case Object Loop; Deaf receive = {case _ = & gt; Val sleepTime = scala.util.Random.nextInt (1000) Thread sleep (sleep time) println ("Manufacturer% s sends food" format name) Pool! Name yourself! Loop // Send a message to yourself}}
scheduler to schedule a message. Manufacturer
preStart () def override: unit = {import scala.concurrent.duration._ import context.dispatcher context.system.scheduler.schedule ( Initial Dailay = 0.seconds, interval = 1.second, receiver = pool, message = name)}
Comments
Post a Comment