com.sun.grizzly.util
Class FixedThreadPool

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by com.sun.grizzly.util.AbstractThreadPool
          extended by com.sun.grizzly.util.FixedThreadPool
All Implemented Interfaces:
ExtendedThreadPool, Thread.UncaughtExceptionHandler, Executor, ExecutorService
Direct Known Subclasses:
DefaultThreadPool

public class FixedThreadPool
extends AbstractThreadPool

minimalistic fixed threadpool to allow for nice scalability if a good Queue impl is used. by default: WorkerThreadImpl is used,

Author:
gustav trede

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.grizzly.util.AbstractThreadPool
AbstractThreadPool.Worker
 
Field Summary
protected  BlockingQueue<Runnable> workQueue
           
 
Fields inherited from class com.sun.grizzly.util.AbstractThreadPool
activeThreadsCount, byteBufferType, corePoolSize, currentPoolSize, DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT, DEFAULT_MAX_TASKS_QUEUED, DEFAULT_MAX_THREAD_COUNT, DEFAULT_MIN_THREAD_COUNT, initialByteBufferSize, keepAliveTime, maxPoolSize, name, poison, priority, probe, running, statelock, threadFactory, workers
 
Constructor Summary
FixedThreadPool()
          creates a fixed pool of size 8
FixedThreadPool(int size)
           
FixedThreadPool(int poolsize, BlockingQueue<Runnable> workQueue, ThreadFactory threadfactory)
           
FixedThreadPool(int poolsize, String name)
           
FixedThreadPool(int poolsize, ThreadFactory threadfactory)
           
FixedThreadPool(String name, int poolsize, BlockingQueue<Runnable> workQueue, ThreadFactory threadfactory)
           
FixedThreadPool(String name, int poolsize, BlockingQueue<Runnable> workQueue, ThreadFactory threadfactory, ThreadPoolMonitoringProbe probe)
           
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
          not supported
 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.
 Queue<Runnable> getQueue()
          Returns the task queue used by this executor.
 int getQueueSize()
          Returns the number of tasks, which are currently waiting in the queue.
 int getTaskCount()
          Returns the approximate total number of tasks that have been scheduled for execution.
 boolean isTerminated()
          not supported
 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)
           
 
Methods inherited from class com.sun.grizzly.util.AbstractThreadPool
afterExecute, beforeExecute, drain, getByteBufferType, getCorePoolSize, getDefaultThreadFactory, getInitialByteBufferSize, getKeepAliveTime, getMaximumPoolSize, getName, getPriority, getThreadFactory, isShutdown, nextThreadId, onMaxNumberOfThreadsReached, onTaskCompletedEvent, onTaskDequeued, onTaskQueued, onTaskQueueOverflow, onWorkerExit, onWorkerStarted, poisonAll, setByteBufferType, setInitialByteBufferSize, setKeepAliveTime, setName, setPriority, setThreadFactory, shutdown, shutdownNow, startWorker, toString, 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, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
 

Field Detail

workQueue

protected final BlockingQueue<Runnable> workQueue
Constructor Detail

FixedThreadPool

public FixedThreadPool()
creates a fixed pool of size 8


FixedThreadPool

public FixedThreadPool(int size)
Parameters:
size -

FixedThreadPool

public FixedThreadPool(int poolsize,
                       String name)
Parameters:
poolsize -
name -

FixedThreadPool

public FixedThreadPool(int poolsize,
                       ThreadFactory threadfactory)
Parameters:
poolsize -
threadfactory -

FixedThreadPool

public FixedThreadPool(int poolsize,
                       BlockingQueue<Runnable> workQueue,
                       ThreadFactory threadfactory)
Parameters:
poolsize -
workQueue -
threadfactory -

FixedThreadPool

public FixedThreadPool(String name,
                       int poolsize,
                       BlockingQueue<Runnable> workQueue,
                       ThreadFactory threadfactory)
Parameters:
name -
poolsize -
workQueue -
threadfactory -

FixedThreadPool

public FixedThreadPool(String name,
                       int poolsize,
                       BlockingQueue<Runnable> workQueue,
                       ThreadFactory threadfactory,
                       ThreadPoolMonitoringProbe probe)
Parameters:
name -
poolsize -
workQueue -
threadfactory -
probe -
Method Detail

setMaximumPoolSize

public final void setMaximumPoolSize(int maximumPoolSize)
Description copied from class: AbstractThreadPool
Sets the maximum allowed number of threads. This overrides any value set in the constructor. If the new value is smaller than the current value, excess existing threads will be terminated when they next become idle.

Specified by:
setMaximumPoolSize in interface ExtendedThreadPool
Overrides:
setMaximumPoolSize in class AbstractThreadPool
Parameters:
maximumPoolSize - the new maximum
See Also:
ExtendedThreadPool.getMaximumPoolSize()

execute

public void execute(Runnable command)

isTerminated

public boolean isTerminated()
not supported


awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
not supported

Throws:
InterruptedException

getActiveCount

public int getActiveCount()
Description copied from interface: ExtendedThreadPool
Returns the approximate number of threads that are actively executing tasks.

Returns:
the number of threads

getTaskCount

public int getTaskCount()
Description copied from interface: ExtendedThreadPool
Returns the approximate total number of tasks that have been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.

Returns:
the number of tasks

getCompletedTaskCount

public long getCompletedTaskCount()
Description copied from interface: ExtendedThreadPool
Returns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.

Returns:
the number of tasks

setCorePoolSize

public void setCorePoolSize(int corePoolSize)
Description copied from class: AbstractThreadPool
Sets the core number of threads. This overrides any value set in the constructor. If the new value is smaller than the current value, excess existing threads will be terminated when they next become idle. If larger, new threads will, if needed, be started to execute any queued tasks.

Specified by:
setCorePoolSize in interface ExtendedThreadPool
Overrides:
setCorePoolSize in class AbstractThreadPool
Parameters:
corePoolSize - the new core size
See Also:
ExtendedThreadPool.getCorePoolSize()

getLargestPoolSize

public int getLargestPoolSize()
Description copied from interface: ExtendedThreadPool
Returns the largest number of threads that have ever simultaneously been in the pool.

Returns:
the number of threads

getPoolSize

public int getPoolSize()
Description copied from interface: ExtendedThreadPool
Returns the current number of threads in the pool.

Returns:
the number of threads

getQueue

public Queue<Runnable> getQueue()
Description copied from interface: ExtendedThreadPool
Returns the task queue used by this executor. Access to the task queue is intended primarily for debugging and monitoring. This queue may be in active use. Retrieving the task queue does not prevent queued tasks from executing.

Returns:
the task queue

getQueueSize

public int getQueueSize()
Description copied from interface: ExtendedThreadPool
Returns the number of tasks, which are currently waiting in the queue.

Returns:
the number of tasks, which are currently waiting in the queue.

getMaxQueuedTasksCount

public int getMaxQueuedTasksCount()

setMaxQueuedTasksCount

public void setMaxQueuedTasksCount(int maxTasksCount)


Copyright © 2012 Oracle Corporation. All Rights Reserved.