public class VTNThreadPool extends AbstractExecutorService implements AutoCloseable
VTNThreadPool implements thread pool which executes each
submitted task using pooled threads.
Submitted tasks are executed on worker threads in the pool. The first worker thread, called main thread, is created when the pool is created, and it never exits. When a new task is submitted to thread pool, and the number of worker threads in the pool is less than the thread pool size, a new thread is created to execute the task. Worker threads except for main thread will be terminated if they have been idle for the keep-alive time.
| Modifier and Type | Class and Description |
|---|---|
protected class |
VTNThreadPool.WorkerThread
WorkerThread class implements worker threads in thread pool. |
| Constructor and Description |
|---|
VTNThreadPool(String prefix)
Construct a new thread pool which has a single worker thread.
|
VTNThreadPool(String prefix,
int size,
long keep)
Construct a new thread pool.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit)
Block the calling thread until all tasks in this pool have completed
execution after a shut down request.
|
void |
close()
Close this thread pool instance.
|
void |
execute(Runnable task)
Execute the specified task on one of worker threads in the pool.
|
boolean |
executeTask(Runnable task)
Execute the specified task on one of worker threads in the pool.
|
protected void |
finalize()
Finalize the thread pool.
|
boolean |
isAlive()
Determine whether this thread pool is alive or not.
|
boolean |
isShutdown()
Determine whether this thread pool is already shut down or not.
|
boolean |
isTerminated()
Determine whether all tasks in this thread pool have completed after a
shut down request.
|
protected <T> RunnableFuture<T> |
newTaskFor(Callable<T> callable)
Return a
RunnableFuture instance for the given callable task. |
protected <T> RunnableFuture<T> |
newTaskFor(Runnable runnable,
T value)
Return a
RunnableFuture instance for the given runnable and
return value. |
void |
shutdown()
Shut down the thread pool.
|
List<Runnable> |
shutdownNow()
Shut down the thread pool, and attempt to stop all executing tasks.
|
public VTNThreadPool(String prefix)
prefix - A prefix for the name of worker threads.public VTNThreadPool(String prefix, int size, long keep)
prefix - A prefix for the name of worker threads.size - The maximum number of threads in the pool.keep - Timeout value in milliseconds for idle threads waiting
for task.public boolean executeTask(Runnable task)
task - A task to be executed on this thread pool.true is returned if the specified task was submitted.
false is returned if the specified tas was rejected.IllegalArgumentException - task is null.public boolean isAlive()
true only if this thread pool is alive.protected void finalize()
throws Throwable
This method calls terminate() to terminate all worker
threads.
protected <T> RunnableFuture<T> newTaskFor(@Nonnull Runnable runnable, T value)
RunnableFuture instance for the given runnable and
return value.newTaskFor in class AbstractExecutorServiceT - The type of the value to be returned.runnable - The runnable task being wrapped.value - The value for the returned future.RunnableFuture instance.protected <T> RunnableFuture<T> newTaskFor(@Nonnull Callable<T> callable)
RunnableFuture instance for the given callable task.newTaskFor in class AbstractExecutorServiceT - The type of the value to be returned.callable - The callable task being wrapped.RunnableFuture instance.public void shutdown()
After calling method, new tasks will be rejected. Note that this method does not wait for completion of tasks submitted previously.
shutdown in interface ExecutorServicepublic List<Runnable> shutdownNow()
This method interrupts all worker threads in the pool.
shutdownNow in interface ExecutorServicepublic boolean isShutdown()
isShutdown in interface ExecutorServicetrue only if this thread pool is already shut down.public boolean isTerminated()
isTerminated in interface ExecutorServicetrue only if this thread pool is already shut down and
all tasks have completed.public boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface ExecutorServicetimeout - The maximum time to wait.unit - The time unit of the timeout argument.true if all tasks have terminated.
false if at least one task did not complete.InterruptedException - The calling thread was interrupted.public void execute(Runnable task)
execute in interface Executortask - A task to be executed on this thread pool.RejectedExecutionException - The specified task was rejected.NullPointerException - task is null.public void close()
Threads that did not exit within SHUTDOWN_TIMEOUT
milliseconds will be terminated by force.
close in interface AutoCloseableCopyright © 2018 OpenDaylight. All rights reserved.