Javatpoint Logo
Javatpoint Logo

Java ForkJoinPool execute() Method

The (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 1

Test it Now

Output:

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 2

Test it Now

Output:

Common Pool Size before  :0
Common Pool Size after  :3





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials