According to Runnable execute method in Executor, corresponding JAVA doc mentions that it:
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 {@code Executor} implementation.
My doubt is, for example if we create executor service as
ExecutorService executor = Executors.newFixedThreadPool(5);
and create a Runnable task and run it by the above execute method as:
Runnable testRunnableTask = () -> {
Runnable testRunnableTask = () -> {
System.out.println("my tested function");
}
};
executor.execute(testRunnableTask);
Then this testRunnableTask should be executed by one of the threads that we have initialized through our fixed thread pool. But as per JAVA doc it can be executed by new thread or thread pool or calling thread.
If my understanding is correct of JAVA doc, then my doubt is why execute method doesn't always use one of the threads from the pool like other methods of ExecutorService like submit.