Java ForkJoinPool execute() MethodThe (ForkJoinTask<?> task) method arranges for asynchronous execution of given task specified as the parameter. The execute method is overloaded as execute (Runnable task) which is used to execute some command at some time in the future. Syntax:Parameter:Task - the task to execute. Returns:Does not return any value. Throws:NullPointerException RejectedExecutionException Example 1Test it NowOutput: Thread[ForkJoinPool-1-worker-2,5,main] computing: 0 to 2 Thread[ForkJoinPool.commonPool-worker-3,5,main] computing: 5 to 7 Thread[ForkJoinPool.commonPool-worker-1,5,main] computing: 7 to 10 Thread[ForkJoinPool.commonPool-worker-3,5,main] computing: 0 to 2 Thread[ForkJoinPool.commonPool-worker-2,5,main] computing: 2 to 5 89 Thread[ForkJoinPool-1-worker-1,5,main] computing: 2 to 5 Example 2Test it NowOutput: Common Pool Size before :0 Common Pool Size after :3
Next TopicForkjoinpool getActiveThreadCount()
|