|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jini.thread.ThreadPool
final class ThreadPool
ThreadPool is a simple thread pool implementation of the Executor interface. A new task is always given to an idle thread, if one is available; otherwise, a new thread is always created. There is no minimum warm thread count, nor is there a maximum thread count (tasks are never queued unless there are sufficient idle threads to execute them). New threads are created as daemon threads in the thread group that was passed to the ThreadPool instance's constructor. Each thread's name is the prefix NewThreadAction.NAME_PREFIX followed by the name of the task it is currently executing, or "Idle" if it is currently idle.
This implementation uses the Logger
named
com.sun.jini.thread.ThreadPool
to
log information at the following levels:
Level | Description |
---|---|
WARNING | uncaught exception in worker thread |
Nested Class Summary | |
---|---|
private static class |
ThreadPool.Task
Task simply encapsulates a task's Runnable object with its name. |
private class |
ThreadPool.Worker
Worker executes an initial task, and then it executes tasks from the queue, passing away if ever idle for more than the idle timeout value. |
Field Summary | |
---|---|
private int |
idleThreads
threads definitely available to take new tasks |
private static long |
idleTimeout
how long a thread waits in the idle state before passing away |
private Object |
lock
lock guarding all mutable instance state (below) |
private static Logger |
logger
|
private LinkedList |
queue
queues of tasks to execute |
private ThreadGroup |
threadGroup
thread group that this pool's threads execute in |
Constructor Summary | |
---|---|
ThreadPool(ThreadGroup threadGroup)
Creates a new thread group that executes tasks in threads of the given thread group. |
Method Summary | |
---|---|
void |
execute(Runnable runnable,
String name)
Executes the given Runnable action asynchronously in some thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long idleTimeout
private static final Logger logger
private final ThreadGroup threadGroup
private final Object lock
private int idleThreads
private final LinkedList queue
Constructor Detail |
---|
ThreadPool(ThreadGroup threadGroup)
Method Detail |
---|
public void execute(Runnable runnable, String name)
Executor
execute
in interface Executor
runnable
- the Runnable action to executename
- string to include in the name of the thread used
to execute the action
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |