Class DirectExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- com.google.common.util.concurrent.AbstractListeningExecutorService
-
- org.apache.druid.java.util.common.concurrent.DirectExecutorService
-
- All Implemented Interfaces:
com.google.common.util.concurrent.ListeningExecutorService,Executor,ExecutorService
public class DirectExecutorService extends com.google.common.util.concurrent.AbstractListeningExecutorServiceCreates an executor service that runs each task in the thread that invokesexecute/submit, as inThreadPoolExecutor.CallerRunsPolicyThis applies both to individually submitted tasks and to collections of tasks submitted viainvokeAllorinvokeAny. In the latter case, tasks will run serially on the calling thread. Tasks are run to completion before aFutureis returned to the caller (unless the executor has been shutdown).Although all tasks are immediately executed in the thread that submitted the task, this
ExecutorServiceimposes a small locking overhead on each task submission in order to implement shutdown and termination behavior.The implementation deviates from the
ExecutorServicespecification with regards to theshutdownNowmethod. First, "best-effort" with regards to canceling running tasks is implemented as "no-effort". No interrupts or other attempts are made to stop threads executing tasks. Second, the returned list will always be empty, as any submitted task is considered to have started execution. This applies also to tasks given toinvokeAllorinvokeAnywhich are pending serial execution, even the subset of the tasks that have not yet started execution. It is unclear from theExecutorServicespecification if these should be included, and it's much easier to implement the interpretation that they not be. Finally, a call toshutdownorshutdownNowmay result in concurrent calls toinvokeAll/invokeAnythrowing RejectedExecutionException, although a subset of the tasks may already have been executed.
-
-
Constructor Summary
Constructors Constructor Description DirectExecutorService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable command)booleanisShutdown()booleanisTerminated()voidshutdown()List<Runnable>shutdownNow()-
Methods inherited from class com.google.common.util.concurrent.AbstractListeningExecutorService
newTaskFor, newTaskFor, submit, submit, submit
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAny, invokeAny
-
-
-
-
Method Detail
-
execute
public void execute(Runnable command)
-
isShutdown
public boolean isShutdown()
-
shutdown
public void shutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Throws:
InterruptedException
-
-