Avoids the expense of thread creation by pooling threads after their run methods exit for reuse.
If the maximum pool size is reached, jobs wait for a free thread. By default there is no maximum pool size. Idle threads timeout and terminate until the minimum number of threads are running.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| public class | QueuedThreadPool.
Pool Thread class. |
| Modifier and Type | Field and Description |
|---|---|
| private static int | |
| private boolean | |
| private int | |
| private List | |
| private Runnable[] | |
| private final Object | |
| private long | |
| private final Object | |
| private int | |
| private int | |
| private int | |
| private int | |
| private int | |
| private int | |
| private String | |
| private int | |
| private int | |
| private int | |
| private int | |
| private int | |
| private Set | |
| private final Object | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| protected void | |
| protected void | |
| public int | Returns: Number of threadsImplements org. |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public String | |
| public int | |
| public int | Returns: the spawnOrShrinkAt The number of queued jobs (or idle threads) needed before the thread pool is grown (or shrunk)
|
| public int | Returns: Number of threadsImplements org. |
| public int | |
| public boolean | |
| public boolean | |
| public void | |
| protected void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setSpawnOrShrinkAt(int
The number of queued jobs (or idle threads) needed
before the thread pool is grown (or shrunk) spawnOrShrinkAt)
|
| public void | |
| protected void |
| __id | back to summary |
|---|---|
| private static int __id | |
| _daemon | back to summary |
|---|---|
| private boolean _daemon | |
| _id | back to summary |
|---|---|
| private int _id | |
| _idle | back to summary |
|---|---|
| private List<E> _idle | |
| _jobs | back to summary |
|---|---|
| private Runnable[] _jobs | |
| _joinLock | back to summary |
|---|---|
| private final Object _joinLock | |
| _lastShrink | back to summary |
|---|---|
| private long _lastShrink | |
| _lock | back to summary |
|---|---|
| private final Object _lock | |
| _lowThreads | back to summary |
|---|---|
| private int _lowThreads | |
| _maxIdleTimeMs | back to summary |
|---|---|
| private int _maxIdleTimeMs | |
| _maxQueued | back to summary |
|---|---|
| private int _maxQueued | |
| _maxStopTimeMs | back to summary |
|---|---|
| private int _maxStopTimeMs | |
| _maxThreads | back to summary |
|---|---|
| private int _maxThreads | |
| _minThreads | back to summary |
|---|---|
| private int _minThreads | |
| _name | back to summary |
|---|---|
| private String _name | |
| _nextJob | back to summary |
|---|---|
| private int _nextJob | |
| _nextJobSlot | back to summary |
|---|---|
| private int _nextJobSlot | |
| _priority | back to summary |
|---|---|
| private int _priority | |
| _queued | back to summary |
|---|---|
| private int _queued | |
| _spawnOrShrinkAt | back to summary |
|---|---|
| private int _spawnOrShrinkAt | |
| _threads | back to summary |
|---|---|
| private Set<E> _threads | |
| _threadsLock | back to summary |
|---|---|
| private final Object _threadsLock | |
| _warned | back to summary |
|---|---|
| private boolean _warned | |
| QueuedThreadPool | back to summary |
|---|---|
| public QueuedThreadPool() | |
| QueuedThreadPool | back to summary |
|---|---|
| public QueuedThreadPool(int maxThreads) | |
| dispatch | back to summary |
|---|---|
| public boolean dispatch(Runnable job) Implements org. Run job.
| |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception | |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Stop the BoundedThreadPool. New jobs are no longer accepted,idle threads are interrupted and stopJob is called on active threads. The method then waits min(getMaxStopTimeMs(),getMaxIdleTimeMs()), for all jobs to stop, at which time killJob is called. | |
| getIdleThreads | back to summary |
|---|---|
| public int getIdleThreads() Implements org. Get the number of idle threads in the pool.
| |
| getLowThreads | back to summary |
|---|---|
public int getLowThreads()
| |
| getMaxIdleTimeMs | back to summary |
|---|---|
| public int getMaxIdleTimeMs() Get the maximum thread idle time. Delegated to the named or anonymous Pool.
| |
| getMaxQueued | back to summary |
|---|---|
public int getMaxQueued()
| |
| getMaxStopTimeMs | back to summary |
|---|---|
public int getMaxStopTimeMs()
| |
| getMaxThreads | back to summary |
|---|---|
| public int getMaxThreads() Set the maximum number of threads. Delegated to the named or anonymous Pool.
| |
| getMinThreads | back to summary |
|---|---|
| public int getMinThreads() Get the minimum number of threads. Delegated to the named or anonymous Pool.
| |
| getName | back to summary |
|---|---|
public String getName()
| |
| getQueueSize | back to summary |
|---|---|
| public int getQueueSize() | |
| getSpawnOrShrinkAt | back to summary |
|---|---|
public int getSpawnOrShrinkAt()
| |
| getThreads | back to summary |
|---|---|
| public int getThreads() Implements org. Get the number of threads in the pool.
| |
| getThreadsPriority | back to summary |
|---|---|
| public int getThreadsPriority() Get the priority of the pool threads.
| |
| isDaemon | back to summary |
|---|---|
| public boolean isDaemon() Delegated to the named or anonymous Pool. | |
| isLowOnThreads | back to summary |
|---|---|
| public boolean isLowOnThreads() Implements org.
| |
| join | back to summary |
|---|---|
| public void join() throws InterruptedException Implements org. Doc from org. Blocks until the thread pool is | |
| newThread | back to summary |
|---|---|
| protected void newThread() | |
| setDaemon | back to summary |
|---|---|
| public void setDaemon(boolean daemon) Delegated to the named or anonymous Pool. | |
| setLowThreads | back to summary |
|---|---|
public void setLowThreads(int lowThreads)
| |
| setMaxIdleTimeMs | back to summary |
|---|---|
| public void setMaxIdleTimeMs(int maxIdleTimeMs) Set the maximum thread idle time. Threads that are idle for longer than this period may be stopped. Delegated to the named or anonymous Pool.
| |
| setMaxStopTimeMs | back to summary |
|---|---|
public void setMaxStopTimeMs(int stopTimeMs)
| |
| setMaxThreads | back to summary |
|---|---|
| public void setMaxThreads(int maxThreads) Set the maximum number of threads. Delegated to the named or anonymous Pool.
| |
| setMinThreads | back to summary |
|---|---|
| public void setMinThreads(int minThreads) Set the minimum number of threads. Delegated to the named or anonymous Pool.
| |
| setName | back to summary |
|---|---|
public void setName(String name)
| |
| setSpawnOrShrinkAt | back to summary |
|---|---|
public void setSpawnOrShrinkAt(int spawnOrShrinkAt)
| |
| setThreadsPriority | back to summary |
|---|---|
| public void setThreadsPriority(int priority) Set the priority of the pool threads.
| |
| stopJob | back to summary |
|---|---|
| protected void stopJob(Thread thread, Object job) Stop a Job. This method is called by the Pool if a job needs to be stopped. The default implementation does nothing and should be extended by a derived thread pool class if special action is required. | |
| Access | Constructor and Description |
|---|---|
| private |
| Lock | back to summary |
|---|---|
| private Lock() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Runnable |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| public void |
| _job | back to summary |
|---|---|
| pack-priv Runnable _job | |
| PoolThread | back to summary |
|---|---|
| pack-priv PoolThread() | |
| dispatch | back to summary |
|---|---|
| pack-priv void dispatch(Runnable job) | |
| run | back to summary |
|---|---|
| public void run() Overrides java. Implements java. BoundedThreadPool run. Loop getting jobs and handling them until idle or stopped. | |