Java ForkJoinPool invoke() MethodThe invoke() method of ForkJoinPool class performs the task specified as the parameter and returns the result on its completion. If the computation encounters an unchecked Exception or Error, it is thrown as the outcome of this invocation. SyntaxParameterT - The type of the task's result ReturnsTask - the task ThrowsNullPointerException - if the task is null RejectedExecutionException - if the task cannot be scheduled for execution Example 1Test it NowOutput: Thread[ForkJoinPool.commonPool-worker-2,5,main] computing: 0 to 2 Thread[ForkJoinPool.commonPool-worker-2,5,main] computing: 2 to 5 Thread[ForkJoinPool-3-worker-1,5,main] computing: 0 to 2 Thread[ForkJoinPool-2-worker-1,5,main] computing: 0 to 2 Thread[ForkJoinPool-1-worker-1,5,main] computing: 0 to 2 Thread[ForkJoinPool-1-worker-1,5,main] computing: 2 to 5 Thread[ForkJoinPool.commonPool-worker-2,5,main] computing: 5 to 7 Thread[ForkJoinPool.commonPool-worker-1,5,main] computing: 7 to 10 87 Example 2Test it NowOutput: Common Pool Size before :0 Common Pool Size after :3
Next TopicJava ForkJoinPool
|