4
votes

i have a java application which has various Agents(Java Algo's) which listen to messages and process them . Each agent executes these messages on a single thread where these messages are added in a blocking queue to be processed one by one . This processing on a single message involves i/o with a remote machine . Overtime , these threads get hung one by one due to an inherent Bug in java . They say the bug is fixed but its not , i have run it on all latest java versions and tried all workarounds for a month now .So, i am planning to move to scala actors .

Below are my questions :

  1. Is the above requirement possible in scala actors and will it overcome the java bug ?

  2. A simple overview of how to do it if it's possible :)

    P.S : i have been reading through the programming in scala book for getting the syntax and basic features .

3

3 Answers

1
votes

The bug you cite is a jvm bug. Therefore, if you're using the 'same' code on the same JVM, you'll still experience the bug. Scala still runs on the JVM, so there is still a chance that you'll come across the same bug.

Scala Actors probably won't exercise the JVM in the same way. But you can't guarantee anything. Try it and see.

1
votes

If you're just getting started with the actor model, I highly recommend using the actors package from akka.io. When I started dabbling I had some problems when using the standard Scala remote actors library. I have heard also that in time, the akka actor implementation will replace the current one in the Scala standard library.

This doesn't address your question per se, but writing Actor based concurrent programs is a lot simpler than managing your own critical sections -- at least that has been my experience.

1
votes
  1. For the first question the answer is yes , scala actors do overcome the bug mentioned due to its actor concurrency model . I have been using it over the past 2 weeks with no downtime . Actors are lightweight , easy to scale and are definetly performing faster than my threaded agents in java . The memory consumption has come down as well weirdly.

  2. Now for the implementation part , writing actors is easy once you know the basics of scala . If you are using eclipse + maven plugin m2eclipse-scala is the place to start . i have successfully built an osgi bundle using the steps mentioned there . The scala ide is a work in progress and is a bit of pain to write code .

  3. Now for the scala actors , working with their message inbox's is hard . Accessing them is restricted and they seem to easily get out of memory when the rate of message's coming in is higher than the rate at which the actor could process . Akka actors definitely have an advantage here in by enabling us to set the max mailbox size,mailbox-push-timeout..etc or you can have your own inbox implementation .

Thanks for you help

sanre6