public class AtmostOneThreadExecutor extends AbstractExecutorService
ExecutorService
that uses at most one executor.
Compared to Executors.newFixedThreadPool(1)
, this code will not keep
the thread around if it's not doing anything, freeing up resources.
Constructor and Description |
---|
AtmostOneThreadExecutor() |
AtmostOneThreadExecutor(ThreadFactory factory) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit) |
void |
execute(Runnable command) |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
List<Runnable> |
shutdownNow() |
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
public AtmostOneThreadExecutor(ThreadFactory factory)
public AtmostOneThreadExecutor()
public void shutdown()
public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
public void execute(Runnable command)
Copyright © 2014. All rights reserved.