Search code examples
javaalgorithmmultithreadingmulticore

How can I implement an algorithm for multicore in Java?


Modern computers have more and more cores. We want to change our current linear algorithm to use these cores.

A splitting of any algorithm to use different threads only makes sense if there is a free processor.

Are there any good libraries that can help to parallelize some steps if there are free processors?

I will give some examples.

  • If there is only one processor it makes no sense to create multiple threads. It will reduce the speed.
  • If there run 2 processes (requests on a server) on a core duo it make also no sense to start threads.
  • If there only one process on a core duo it make sense.

The abstract algorithm has 4 steps A, B, C and D. Steps A, B and C can execute parallel. Step D needs the results from A, B and C.

Edit: I means an mathematic algorithm. No IO, No events, etc


Solution

  • I think you need a ConcurrentContext from Javolution. See at http://javolution.org/target/site/apidocs/javolution/context/ConcurrentContext.html