@ThreadSafe
public class ThreadExecutor
extends Object
implements ExecutorService, Runnable
| Constructor and Description |
|---|
ThreadExecutor(Optional<Logger> logger)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit) |
void |
execute(Runnable runnable) |
<T> T |
invoke(Callable<T> callable)
Invokes a callable from inside the thread.
|
<T> T |
invoke(Callable<T> callable,
long timeout,
TimeUnit unit)
Invokes a callable from inside the thread.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> callables) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> callables,
long timeout,
TimeUnit unit) |
<T> T |
invokeAny(Collection<? extends Callable<T>> callables) |
<T> T |
invokeAny(Collection<? extends Callable<T>> callables,
long timeout,
TimeUnit unit) |
boolean |
isBusy()
Asks if this executor is busy.
|
boolean |
isRunning()
Asks if this executor is running.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
reset(Optional<String> threadName,
boolean daemonThread)
Resets.
|
void |
run() |
void |
shutdown() |
List<Runnable> |
shutdownNow() |
void |
startThread()
Starts the thread.
|
<T> Future<T> |
submit(Callable<T> callable) |
Future<?> |
submit(Runnable runnable) |
<T> Future<T> |
submit(Runnable runnable,
T result) |
public ThreadExecutor(@Nonnull
Optional<Logger> logger)
logger - An optional logger.public boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface ExecutorServiceInterruptedExceptionpublic void execute(Runnable runnable)
execute in interface Executor@CheckReturnValue
public <T> T invoke(@Nonnull
Callable<T> callable)
throws InterruptedException,
ExecutionException
T - The type returned by the callable.callable - The callable.InterruptedException - When the invoke is interrupted.ExecutionException - When the callable throws something.@CheckReturnValue
public <T> T invoke(Callable<T> callable,
long timeout,
TimeUnit unit)
throws InterruptedException,
ExecutionException,
TimeoutException
T - The type returned by the callable.callable - The callable.timeout - The maximum time to wait.unit - The time ounit of the timeout.InterruptedException - When the invoke is interrupted.ExecutionException - When the callable throws something.TimeoutException - If the timeout elapses.public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables)
throws InterruptedException
invokeAll in interface ExecutorServiceInterruptedExceptionpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables,
long timeout,
TimeUnit unit)
throws InterruptedException
invokeAll in interface ExecutorServiceInterruptedExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> callables)
throws InterruptedException,
ExecutionException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> callables,
long timeout,
TimeUnit unit)
throws InterruptedException,
ExecutionException,
TimeoutException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionTimeoutException@CheckReturnValue public boolean isBusy()
@CheckReturnValue public boolean isRunning()
public boolean isShutdown()
isShutdown in interface ExecutorServicepublic boolean isTerminated()
isTerminated in interface ExecutorServicepublic void reset(@Nonnull
Optional<String> threadName,
boolean daemonThread)
threadName - The optional thread name.daemonThread - Sets the thread as daemon if true.public void run()
run in interface Runnablepublic void shutdown()
shutdown in interface ExecutorServicepublic List<Runnable> shutdownNow()
shutdownNow in interface ExecutorServicepublic void startThread()
public <T> Future<T> submit(Callable<T> callable)
submit in interface ExecutorServicepublic Future<?> submit(Runnable runnable)
submit in interface ExecutorServicepublic <T> Future<T> submit(Runnable runnable,
T result)
submit in interface ExecutorServiceCopyright © 2003-2019 Serge Brisson. All Rights Reserved.