public class SingleThreadExecutor extends Object implements Runnable, ExecutorService
| Constructor and Description |
|---|
SingleThreadExecutor()
Creates a single thread executor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit)
This method is unsupported by this implementation.
|
void |
execute(Runnable r)
Executes the given command at some time in the future.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks)
This method is unsupported by this implementation.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit)
This method is unsupported by this implementation.
|
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks)
This method is unsupported by this implementation.
|
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit)
This method is unsupported by this implementation.
|
boolean |
isShutdown()
Returns true if this executor has been shut down.
|
boolean |
isTerminated()
Returns true if all tasks have completed following shut down.
|
void |
run()
When an object implementing interface
Runnable is used to create a thread, starting
the thread causes the object's run method to be called in that separately executing
thread. |
void |
shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be
accepted.
|
List<Runnable> |
shutdownNow()
This method is unsupported by this implementation.
|
<T> Future<T> |
submit(Callable<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task.
|
Future<?> |
submit(Runnable task)
This method is unsupported by this implementation.
|
<T> Future<T> |
submit(Runnable task,
T result)
This method is unsupported by this implementation.
|
public SingleThreadExecutor()
A new thread is created and started immediately.
public boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
Calling this method will throw an UnsupportedOperationException.
awaitTermination in interface ExecutorServicetimeout - the maximum time to waitunit - the time unit of the timeout argumentInterruptedException - if interrupted while waitingpublic void execute(Runnable r)
Executorpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
Calling this method will throw an UnsupportedOperationException.
invokeAll in interface ExecutorServicetasks - the collection of tasksInterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled.public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
Calling this method will throw an UnsupportedOperationException.
invokeAll in interface ExecutorServicetasks - the collection of taskstimeout - the maximum time to waitunit - the time unit of the timeout argumentInterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelledpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
Calling this method will throw an UnsupportedOperationException.
invokeAny in interface ExecutorServicetasks - the collection of tasksInterruptedException - if interrupted while waitingExecutionException - if no task successfully completespublic <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Calling this method will throw an UnsupportedOperationException.
invokeAny in interface ExecutorServicetasks - the collection of taskstimeout - the maximum time to waitunit - the time unit of the timeout argumentInterruptedException - if interrupted while waitingExecutionException - if no task successfully completesTimeoutException - if the given timeout elapses before any task successfully completespublic boolean isShutdown()
ExecutorServiceisShutdown in interface ExecutorServicepublic boolean isTerminated()
ExecutorServiceisTerminated in interface ExecutorServicepublic void run()
RunnableRunnable is used to create a thread, starting
the thread causes the object's run method to be called in that separately executing
thread.
The general contract of the method run is that it may take any action whatsoever.
run in interface RunnableThread.run()public void shutdown()
ExecutorService
This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.
shutdown in interface ExecutorServicepublic List<Runnable> shutdownNow()
Calling this method will throw an UnsupportedOperationException.
shutdownNow in interface ExecutorServicepublic <T> Future<T> submit(Callable<T> task)
ExecutorServiceIf you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();
submit in interface ExecutorServicetask - the task to submitpublic Future<?> submit(Runnable task)
Calling this method will throw an UnsupportedOperationException.
submit in interface ExecutorServicetask - the task to submitpublic <T> Future<T> submit(Runnable task, T result)
Calling this method will throw an UnsupportedOperationException.
submit in interface ExecutorServicetask - the task to submitresult - the result to return