Fork/Join Framework
Fork/join framework is for implementing parallel processing in java. It extends the java 6 multi-threading to take advantage of multiple processors in the hardware. Though it is effective only for problems which are inherently recursive( can be written as recursive ). Till Java 6 , the idea behind multi-threading was to take advantage of free cpu cycles while it is processing one thread/process. The idea behind fork/join is to maximize the usage of multiple processors. So both are designed with slightly different objectives. You may not even notice the difference in performance if the problem is not really recursive. fork/join is also implementation of ExecutorService interface. But it goes one step ahead and takes care of invoking different threads itself in the thread pool rather than developer. It just asks developer to write the tasks in recursive format , it can divide and conquer and run those small -small tasks in different threads in work stealing manner. See the link below in References. For fork/join to be effective you actually need multi-core hardware, not for multi-threading. java.util.Arrays class has parallelSort() methods which utilizes fork/join framework.
References:
https://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
Comments
Post a Comment