@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 ExecutorService
InterruptedException
public 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 ExecutorService
InterruptedException
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables, long timeout, TimeUnit unit) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
public <T> T invokeAny(Collection<? extends Callable<T>> callables) throws InterruptedException, ExecutionException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
public <T> T invokeAny(Collection<? extends Callable<T>> callables, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
TimeoutException
@CheckReturnValue public boolean isBusy()
@CheckReturnValue public boolean isRunning()
public boolean isShutdown()
isShutdown
in interface ExecutorService
public boolean isTerminated()
isTerminated
in interface ExecutorService
public 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 Runnable
public void shutdown()
shutdown
in interface ExecutorService
public List<Runnable> shutdownNow()
shutdownNow
in interface ExecutorService
public void startThread()
public <T> Future<T> submit(Callable<T> callable)
submit
in interface ExecutorService
public Future<?> submit(Runnable runnable)
submit
in interface ExecutorService
public <T> Future<T> submit(Runnable runnable, T result)
submit
in interface ExecutorService
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.