Strange behavior: Scala Actors 2.7.7 vs. 2.8-Snapshot?

There are some problems with the code. Foremost among them, don't do this: object ActorApplication extends Application When you use extends Application the way your code is run imposes a number of restrictions, such as not being optimizable by the JIT and, of particular relevance to your case, threads won't work correctly. I find it harder to explain what happened on 2.7.7 than what happened on 2.8.Instead, just write a normal object, and define the main method Other stuff: gearController!

StartSync() Don't do this. Always send a message to an actor from inside an actor, and this line is inside ActorApplication constructor, which is not an actor.In situations like this, you can do this: Actor. Actor { gearController!

StartSync() } Speaking of StartSync don't do this: case class StartSync A class without parameters is meaningless (and deprecated). Instead, do this: case object StartSync and drop the parenthesis after StartSync in the places where you use it Also, there's nothing wrong with scala.util. Random though it was easier to misuse it on Scala 2.7 than it is on Scala 2.8, by creating a new Random generator every time you needed a random number (which is what you do in the code).

Instead, on Scala 2.8, just this ought to work: private var mySpeed = scala.util.Random. NextInt(1000) Finally, there's nothing wrong with either execution, it's just the scheduler that's different between them. In fact, given that you created a hundred actors, the GearController was receiving a disproportional amount of execution time in the Scala 2.7 version, as Scala doesn't create a thread for every actor Now, if you want GearController not to share a thread with the others, you should use while(true) receive instead of loop react like this: while(true) { receive { case StartSync => { Which will produce a result quite similar to what 2.7 produced.

There are some problems with the code. Foremost among them, don't do this: object ActorApplication extends Application When you use extends Application, the way your code is run imposes a number of restrictions, such as not being optimizable by the JIT and, of particular relevance to your case, threads won't work correctly. I find it harder to explain what happened on 2.7.7 than what happened on 2.8.Instead, just write a normal object, and define the main method.

Other stuff: gearController! StartSync() Don't do this. Always send a message to an actor from inside an actor, and this line is inside ActorApplication constructor, which is not an actor.

In situations like this, you can do this: Actor. Actor { gearController!StartSync() } Speaking of StartSync, don't do this: case class StartSync A class without parameters is meaningless (and deprecated). Instead, do this: case object StartSync and drop the parenthesis after StartSync in the places where you use it.

Also, there's nothing wrong with scala.util. Random, though it was easier to misuse it on Scala 2.7 than it is on Scala 2.8, by creating a new Random generator every time you needed a random number (which is what you do in the code). Instead, on Scala 2.8, just this ought to work: private var mySpeed = scala.util.Random.

NextInt(1000) Finally, there's nothing wrong with either execution, it's just the scheduler that's different between them. In fact, given that you created a hundred actors, the GearController was receiving a disproportional amount of execution time in the Scala 2.7 version, as Scala doesn't create a thread for every actor. Now, if you want GearController not to share a thread with the others, you should use while(true)/receive instead of loop/react, like this: while(true) { receive { case StartSync => { Which will produce a result quite similar to what 2.7 produced.

1 Thank you Daniel for your helpful answer. I did the changes and my code runs well in Scala 2.8. I'll do a simple Scala-swing-GUI for this simulation and publish it on github. – pmeiclx Feb 11 '10 at 13:02.

Private val random = new Random() //scala. Private var mySpeed = random. Controller Send commands for syncing to gears!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions