emchristiansen
emchristiansen

Reputation: 3602

Process-level parallelism in Scala

I'd like to use reflection in combination with parallel processing in Scala, but I'm getting bitten by reflection's lack of thread safety. So, I'm considering just running each task in its own process (not thread). Is there any easy way to do this?

For example, is there a way to configure .par so it spawns processes, not threads? Or is there some function fork that takes a closure and runs it in a new process?

EDIT: Futures are apparently a good way to go. However, I still need to figure out how to run them in separate processes.

EDIT 2: I'm still having concurrency issues, even when using Akka's "fork-join-executor" dispatcher, which sure sounds like it should be forking processes. However, when I run ManagementFactory.getRuntimeMXBean().getName() inside the Futures, it seems everything still lives in the same process. Is this the right way to check for actual process-level parallelism? Am I using the correct Akka dispatcher?

EDIT 3: I realize reflection sucks. Unfortunately it is used in a library I need.

Upvotes: 2

Views: 335

Answers (2)

Jonny Coombes
Jonny Coombes

Reputation: 575

There's little information as regards the problem you're trying to solve here...previous answers are pretty much on the ball - look at Actors etc...Akka and you may find that you don't need to necessarily do anything too complicated. Introspection/reflection in a multi-threaded environment usually means a messy and not well thought-out strategy in terms of decomposing the problem in hand.

Upvotes: 0

Vidya
Vidya

Reputation: 30300

Have you looked into Scala Actors or Akka? There may be no more compelling reason to use Scala than for parallel and asynchronous programming. It's baked into the language. Check out these facilities. I'm pretty sure you'll find what you need.

Upvotes: 4

Related Questions