Home > DeveloperSection > Interviews > Where to use fork/join as opposed to using the ExecutorService framework?

Posted on    September-05-2015 6:36 AM

 Java Java  Thread  Multiple Threading 
 1 Answer(s)
  465  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    September-05-2015 6:36 AM

The Fork/Join Framework in Java 7 is designed for work that can be broken down into smaller tasks and the results of those tasks combined to produce the final result. Multicore processors are now widespread across server, desktop, and laptop hardware. They are also making their way into smaller devices, such as smartphones and tablets. Fork/Join offers serious gains for solving problems that involve recursion.

The fork/join tasks should operate as “pure” in-memory algorithms in which no I/O operations come into play. Also, communication between tasks through shared state should be avoided as much as possible, because that implies that locking might have to be performed. Ideally, tasks communicate only when one task forks another or when one task joins another.

ExecutorService continues to be a fine solution for many concurrent programming tasks, and in programming scenarios in which recursion is vital to processing power, it makes sense to use Fork/join. This fork and join feature is used in Java 8 parallel stream processing with lambda expressions

Don't want to miss updates? Please click the below button!

Follow MindStick