aspose file tools*
The moose likes Scala and the fly likes Do Scala Actors have Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Scala
Bookmark "Do Scala Actors have "spawn"" Watch "Do Scala Actors have "spawn"" New topic
Author

Do Scala Actors have "spawn"

Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

An Erlang book I'm reading says Erlang has 3 main parts with concurrency: receiving a message, sending a message (!), and spawning a process.

So Erlang has this thing called spawn. Does something like this exist in Scala?


A good workman is known by his tools.
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Not sure of what "spawn" does, but I guess it will be equivalent to:
Although Scala implements the concept of actors, I think Erlang provides better support for low-cost concurrency and recovery.
On the other hand, running in the JVM is a big plus and with Terracota you can get almost free clustering.
[ August 07, 2008: Message edited by: Gabriel Claramunt ]

Gabriel
Software Surgeon
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I think you're right, Gabriel.

Doesn't Scala still use Java-style threads? Aren't they kind of expensive to create?

The Erlang book encourages creating lots and lots of processes - to the point that I think having them in the thousands is good.

Has anyone seen any process-creation benchmarks of Erlang vs Scala? I have a funny feeling the JVM can't keep up on process creation... or at least not yet.
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Actually,I just found that Scala's event-based actors are threadless. Scala uses a pool of threads to serve all actor requests. If I recall correctly, Erlang does something similar.
In event based actors, messages are processed with the "react" keyword instead of "receive", the Actors tutorial explains how to use it
Also I found a detailed explanation of what happens behind the curtains in Event-Based Programming without Inversion of Control
Seems Scala's actors are almost like Erlang ones
[ August 11, 2008: Message edited by: Gabriel Claramunt ]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Originally posted by Marc Peabody:
Doesn't Scala still use Java-style threads? Aren't they kind of expensive to create?


Not if you use a thread pool. That's why they were put in Java long ago.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do Scala Actors have "spawn"