/
T1.scala
executable file
·39 lines (28 loc) · 888 Bytes
/
T1.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.tiger
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
object Print{
val count = new AtomicInteger(0)
}
class Print extends Actor with ActorLogging{
override def receive = {
case (v1:ActorRef,v2:ActorRef) =>
for(i <- 1 to 5){
log.debug("{}",Print.count.incrementAndGet())
TimeUnit.MILLISECONDS.sleep(100)
}
if(Print.count.get()<75){
v1 ! (v2,self)
}
}
}
object T1 {
def main(args: Array[String]): Unit = {
val system = ActorSystem.create()
val v1 = system.actorOf(Props[Print].withDispatcher("print-dispatcher"))
val v2 = system.actorOf(Props[Print].withDispatcher("print-dispatcher"))
val v3 = system.actorOf(Props[Print].withDispatcher("print-dispatcher"))
v1 ! (v2,v3)
}
}