|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.concurrent.AbstractExecutorService
com.sun.grizzly.util.AbstractThreadPool
com.sun.grizzly.util.FixedThreadPool
public class FixedThreadPool
minimalistic fixed threadpool.
by default: WorkerThreadImpl is used,
LinkedTransferQueue is used as workQueue for its nice scalability over the lock based alternatives.
LinkedTransferQueue gives FIFO per producer.
| Nested Class Summary | |
|---|---|
protected class |
FixedThreadPool.BasicWorker
|
| Nested classes/interfaces inherited from class com.sun.grizzly.util.AbstractThreadPool |
|---|
AbstractThreadPool.Worker |
| Field Summary | |
|---|---|
protected AtomicInteger |
aliveworkerCount
exits for use by subclasses, does not impact the performance of fixed pool |
protected AtomicInteger |
approximateRunningWorkerCount
|
protected boolean |
running
|
protected Object |
statelock
|
protected ConcurrentHashMap<AbstractThreadPool.Worker,Boolean> |
workers
|
protected BlockingQueue<Runnable> |
workQueue
|
| Fields inherited from class com.sun.grizzly.util.AbstractThreadPool |
|---|
byteBufferType, corePoolSize, DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT, DEFAULT_MAX_TASKS_QUEUED, DEFAULT_MAX_THREAD_COUNT, DEFAULT_MIN_THREAD_COUNT, initialByteBufferSize, keepAliveTime, maxPoolSize, name, poison, priority, threadFactory |
| Constructor Summary | |
|---|---|
|
FixedThreadPool()
creates a fixed pool of size 8 |
protected |
FixedThreadPool(BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory)
|
|
FixedThreadPool(int size)
|
|
FixedThreadPool(int fixedsize,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadfactory)
|
|
FixedThreadPool(int size,
String name)
|
|
FixedThreadPool(int size,
ThreadFactory threadfactory)
|
| Method Summary | |
|---|---|
protected void |
afterExecute(Runnable r,
Throwable t)
Method invoked upon completion of execution of the given Runnable. |
boolean |
awaitTermination(long timeout,
TimeUnit unit)
not supported |
protected void |
beforeExecute(Thread t,
Runnable r)
Method invoked prior to executing the given Runnable in the given thread. |
void |
execute(Runnable command)
|
int |
getActiveCount()
Returns the approximate number of threads that are actively executing tasks. |
long |
getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution. |
int |
getLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool. |
int |
getMaxQueuedTasksCount()
|
int |
getPoolSize()
Returns the current number of threads in the pool. |
BlockingQueue<Runnable> |
getQueue()
Returns the task queue used by this executor. |
int |
getQueueSize()
Runs at O(n) time with default Impl. |
int |
getTaskCount()
Returns the approximate total number of tasks that have been scheduled for execution. |
boolean |
isShutdown()
|
boolean |
isTerminated()
not supported |
protected String |
nextThreadId()
|
protected void |
onWorkerExit(AbstractThreadPool.Worker worker)
Method is called by AbstractThreadPool.Worker, when it's completing
AbstractThreadPool.Worker.run() method execution, which in most cases means,
that ThreadPool's thread will be released. |
void |
setCorePoolSize(int corePoolSize)
Sets the core number of threads. |
void |
setMaximumPoolSize(int maximumPoolSize)
Sets the maximum allowed number of threads. |
void |
setMaxQueuedTasksCount(int maxTasksCount)
|
void |
shutdown()
|
List<Runnable> |
shutdownNow()
|
protected void |
startWorker(FixedThreadPool.BasicWorker wt)
|
| Methods inherited from class com.sun.grizzly.util.AbstractThreadPool |
|---|
getByteBufferType, getCorePoolSize, getInitialByteBufferSize, getKeepAliveTime, getMaximumPoolSize, getName, getPriority, getThreadFactory, onMaxNumberOfThreadsReached, onTaskDequeued, onTaskQueued, onTaskQueueOverflow, onWorkerStarted, setByteBufferType, setInitialByteBufferSize, setKeepAliveTime, setName, setPriority, setThreadFactory, uncaughtException, validateNewPoolSize |
| Methods inherited from class java.util.concurrent.AbstractExecutorService |
|---|
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.concurrent.ExecutorService |
|---|
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit |
| Field Detail |
|---|
protected final ConcurrentHashMap<AbstractThreadPool.Worker,Boolean> workers
protected final AtomicInteger aliveworkerCount
protected final AtomicInteger approximateRunningWorkerCount
protected final BlockingQueue<Runnable> workQueue
protected final Object statelock
protected volatile boolean running
| Constructor Detail |
|---|
public FixedThreadPool()
public FixedThreadPool(int size)
size -
public FixedThreadPool(int size,
String name)
size - name -
public FixedThreadPool(int size,
ThreadFactory threadfactory)
size - threadfactory - ThreadFactory
public FixedThreadPool(int fixedsize,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadfactory)
fixedsize - workQueue -
protected FixedThreadPool(BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory)
| Method Detail |
|---|
protected void startWorker(FixedThreadPool.BasicWorker wt)
public void execute(Runnable command)
public List<Runnable> shutdownNow()
public void shutdown()
public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
InterruptedExceptionpublic int getActiveCount()
public int getTaskCount()
public long getCompletedTaskCount()
public void setCorePoolSize(int corePoolSize)
setCorePoolSize in interface ExtendedThreadPoolsetCorePoolSize in class AbstractThreadPoolcorePoolSize - the new core sizeExtendedThreadPool.getCorePoolSize()public int getLargestPoolSize()
public int getPoolSize()
public BlockingQueue<Runnable> getQueue()
public int getQueueSize()
public void setMaximumPoolSize(int maximumPoolSize)
setMaximumPoolSize in interface ExtendedThreadPoolsetMaximumPoolSize in class AbstractThreadPoolmaximumPoolSize - the new maximumExtendedThreadPool.getMaximumPoolSize()public int getMaxQueuedTasksCount()
public void setMaxQueuedTasksCount(int maxTasksCount)
protected void beforeExecute(Thread t,
Runnable r)
This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.beforeExecute at the end of this method.
beforeExecute in class AbstractThreadPoolt - the thread that will run task r.r - the task that will be executed.
protected void afterExecute(Runnable r,
Throwable t)
Note: When actions are enclosed in tasks (such as
FutureTask) either explicitly or via methods such as
submit, these task objects catch and maintain
computational exceptions, and so they do not cause abrupt
termination, and the internal exceptions are not
passed to this method.
This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.afterExecute at the beginning of this method.
afterExecute in class AbstractThreadPoolr - the runnable that has completed.t - the exception that caused termination, or null if
execution completed normally.protected void onWorkerExit(AbstractThreadPool.Worker worker)
AbstractThreadPool.Worker, when it's completing
AbstractThreadPool.Worker.run() method execution, which in most cases means,
that ThreadPool's thread will be released. This method is called from
AbstractThreadPool.Worker's thread.
onWorkerExit in class AbstractThreadPoolprotected String nextThreadId()
nextThreadId in class AbstractThreadPool
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||