Package org.threadly.concurrent
Class SameThreadSubmitterExecutor
- java.lang.Object
-
- org.threadly.concurrent.SameThreadSubmitterExecutor
-
- All Implemented Interfaces:
java.util.concurrent.Executor,SubmitterExecutor
public class SameThreadSubmitterExecutor extends java.lang.Object implements SubmitterExecutor
ASubmitterExecutorthat will run all provided tasks immediately in the same thread that is invoking into it with the task. This is different from calling the runnable directly only in that no exceptions will propagate out. In the case of justexecute(Runnable)thrown exceptions will be provided toExceptionUtils.handleException(Throwable)to be handled. Otherwise thrown exceptions will be represented within their returnedListenableFuture.- Since:
- 1.2.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute(java.lang.Runnable task)static SameThreadSubmitterExecutorinstance()Call to get a default instance of theSameThreadSubmitterExecutor.<T> ListenableFuture<T>submit(java.lang.Runnable task, T result)Submit a task to run as soon as possible.<T> ListenableFuture<T>submit(java.util.concurrent.Callable<T> task)Submit aCallableto run as soon as possible.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.SubmitterExecutor
submit
-
-
-
-
Method Detail
-
instance
public static SameThreadSubmitterExecutor instance()
Call to get a default instance of theSameThreadSubmitterExecutor. Because there is no saved or shared state, the same instance can be reused as much as desired.- Returns:
- a static instance of SameThreadSubmitterExecutor
-
execute
public void execute(java.lang.Runnable task)
- Specified by:
executein interfacejava.util.concurrent.Executor
-
submit
public <T> ListenableFuture<T> submit(java.lang.Runnable task, T result)
Description copied from interface:SubmitterExecutorSubmit a task to run as soon as possible. TheFuture.get()method will return the provided result once the runnable has completed.- Specified by:
submitin interfaceSubmitterExecutor- Type Parameters:
T- type of result for future- Parameters:
task- runnable to be executedresult- result to be returned from resulting future .get() when runnable completes- Returns:
- a future to know when the task has completed
-
submit
public <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task)
Description copied from interface:SubmitterExecutorSubmit aCallableto run as soon as possible. This is needed when a result needs to be consumed from the callable.- Specified by:
submitin interfaceSubmitterExecutor- Type Parameters:
T- type of result returned from the future- Parameters:
task- callable to be executed- Returns:
- a future to know when the task has completed and get the result of the callable
-
-