Question

Here is what the API says about it:

public void execute(Runnable task)

Description copied from interface: Executor
Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling

thread, at the discretion of the Executor implementation.

Parameters:
    task - the runnable task
Throws:
    NullPointerException - if the task is null
    RejectedExecutionException - if the task cannot be scheduled for execution

ForkJoinPool is already an implementation of ExecutorService? what are they talking about? How do I know the behaviour of such a method?

Was it helpful?

Solution

I'm not quite sure what you are asking here, but yes ForkJoinPool is an implementation of ExecutorService. The execute(Runnable) method will schedule a task to be executed by the ForkJoinPool. This task will get executed when a worker thread in the pool is free to conduct such a task. It is essentially the same as submit(Runnable) except that it does not return a ForkJoinTask (In fact if you check the source code you will see that both methods do the same thing, except execute doesn't return the task it submits).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top