Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.actors.Actor
- import scala.actors._
- import scala.actors.Actor._
- import java.util.concurrent.CountDownLatch
- object ScalaActorStarvation {
- def main(args: Array[String]) {
- val iterations = 30
- for (i <- 1 to iterations) {
- new ParallelTesting() ! ""+i
- }
- }
- }
- class DoStuffActor() extends Actor {
- start()
- def act() {
- loop { react {
- case f:(()=>Unit) => System.err.println("do some async shit")
- Thread.sleep(100)
- f()
- }}
- }
- }
- class ParallelTesting extends Actor {
- start()
- def act() {
- loop { react {
- case str:String => val latch = new CountDownLatch(1)
- new DoStuffActor() ! ( ()=>{ println("someCode " + str)
- latch.countDown()
- } )
- latch.await()
- this.exit
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement