Package com.sun.corba.ee.impl.threadpool
Class ThreadPoolImpl
- java.lang.Object
-
- com.sun.corba.ee.impl.threadpool.ThreadPoolImpl
-
- All Implemented Interfaces:
ThreadPool
,java.io.Closeable
,java.lang.AutoCloseable
@ManagedObject @Description("A ThreadPool used by the ORB") public class ThreadPoolImpl extends java.lang.Object implements ThreadPool
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ThreadPoolImpl.WorkerThread
-
Field Summary
Fields Modifier and Type Field Description private int
availableWorkerThreads
private int
currentThreadCount
static int
DEFAULT_INACTIVITY_TIMEOUT
private long
inactivityTimeout
private int
maxWorkerThreads
private int
minWorkerThreads
private java.lang.String
name
private java.util.concurrent.atomic.AtomicLong
processedCount
private static java.util.concurrent.atomic.AtomicInteger
threadCounter
private java.lang.ThreadGroup
threadGroup
private java.util.concurrent.atomic.AtomicLong
totalTimeTaken
(package private) java.util.List<ThreadPoolImpl.WorkerThread>
workers
(package private) java.lang.Object
workersLock
private java.lang.ClassLoader
workerThreadClassLoader
private WorkQueue
workQueue
-
Constructor Summary
Constructors Constructor Description ThreadPoolImpl(int minSize, int maxSize, long timeout, java.lang.String threadpoolName)
Create a bounded thread pool in the current thread group with the current context ClassLoader as the worker thread default ClassLoader.ThreadPoolImpl(int minSize, int maxSize, long timeout, java.lang.String threadpoolName, java.lang.ClassLoader defaultClassLoader)
Create a bounded thread pool in the current thread group with the given ClassLoader as the worker thread default ClassLoader.ThreadPoolImpl(java.lang.String threadpoolName)
Create an unbounded thread pool in the current thread group with the current context ClassLoader as the worker thread default ClassLoader.ThreadPoolImpl(java.lang.ThreadGroup tg, java.lang.String threadpoolName)
Create an unbounded thread pool in the given thread group with the current context ClassLoader as the worker thread default ClassLoader.ThreadPoolImpl(java.lang.ThreadGroup tg, java.lang.String threadpoolName, java.lang.ClassLoader defaultClassLoader)
Create an unbounded thread pool in the given thread group with the given ClassLoader as the worker thread default ClassLoader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
averageWorkCompletionTime()
This method returns the average elapsed time taken to complete a Work item.void
close()
(package private) void
createWorkerThread()
To be called from the WorkQueue to create worker threads when none available.private java.lang.Thread
createWorkerThreadHelper(java.lang.String name)
int
currentNumberOfThreads()
This method will return the current number of threads in the threadpool.long
currentProcessedCount()
This method returns the number of Work items processed by the threadpool(package private) void
decrementCurrentNumberOfThreads()
(package private) void
decrementNumberOfAvailableThreads()
This method will decrement the number of available threads in the threadpool which are waiting for work.WorkQueue
getAnyWorkQueue()
This method will return any instance of the WorkQueue.private static java.lang.ClassLoader
getDefaultClassLoader()
java.lang.String
getName()
This method will return the name of the threadpool.private static int
getUniqueThreadId()
WorkQueue
getWorkQueue(int queueId)
This method will return an instance of the of the WorkQueue given a queueId.long
idleTimeoutForThreads()
This method will return the time in milliseconds when idle threads in the threadpool are removed.(package private) void
incrementCurrentNumberOfThreads()
(package private) void
incrementNumberOfAvailableThreads()
This method will increment the number of available threads in the threadpool which are waiting for work.int
maximumNumberOfThreads()
This method will return the maximum number of threads in the threadpool at any point in time, for the life of the threadpoolint
minimumNumberOfThreads()
This method will return the minimum number of threads maintained by the threadpool.int
numberOfAvailableThreads()
This method will return the number of available threads in the threadpool which are waiting for work.int
numberOfBusyThreads()
This method will return the number of busy threads in the threadpool This method returns a value which is not synchronized.int
numberOfWorkQueues()
This method will return the number of WorkQueues serviced by the threadpool.
-
-
-
Field Detail
-
DEFAULT_INACTIVITY_TIMEOUT
public static final int DEFAULT_INACTIVITY_TIMEOUT
- See Also:
- Constant Field Values
-
threadCounter
private static final java.util.concurrent.atomic.AtomicInteger threadCounter
-
workQueue
private final WorkQueue workQueue
-
availableWorkerThreads
private int availableWorkerThreads
-
currentThreadCount
private int currentThreadCount
-
minWorkerThreads
private final int minWorkerThreads
-
maxWorkerThreads
private final int maxWorkerThreads
-
inactivityTimeout
private final long inactivityTimeout
-
processedCount
private java.util.concurrent.atomic.AtomicLong processedCount
-
totalTimeTaken
private java.util.concurrent.atomic.AtomicLong totalTimeTaken
-
name
private final java.lang.String name
-
threadGroup
private java.lang.ThreadGroup threadGroup
-
workerThreadClassLoader
private final java.lang.ClassLoader workerThreadClassLoader
-
workersLock
final java.lang.Object workersLock
-
workers
java.util.List<ThreadPoolImpl.WorkerThread> workers
-
-
Constructor Detail
-
ThreadPoolImpl
public ThreadPoolImpl(java.lang.String threadpoolName)
Create an unbounded thread pool in the current thread group with the current context ClassLoader as the worker thread default ClassLoader.
-
ThreadPoolImpl
public ThreadPoolImpl(java.lang.ThreadGroup tg, java.lang.String threadpoolName)
Create an unbounded thread pool in the given thread group with the current context ClassLoader as the worker thread default ClassLoader.
-
ThreadPoolImpl
public ThreadPoolImpl(java.lang.ThreadGroup tg, java.lang.String threadpoolName, java.lang.ClassLoader defaultClassLoader)
Create an unbounded thread pool in the given thread group with the given ClassLoader as the worker thread default ClassLoader.
-
ThreadPoolImpl
public ThreadPoolImpl(int minSize, int maxSize, long timeout, java.lang.String threadpoolName)
Create a bounded thread pool in the current thread group with the current context ClassLoader as the worker thread default ClassLoader.
-
ThreadPoolImpl
public ThreadPoolImpl(int minSize, int maxSize, long timeout, java.lang.String threadpoolName, java.lang.ClassLoader defaultClassLoader)
Create a bounded thread pool in the current thread group with the given ClassLoader as the worker thread default ClassLoader.
-
-
Method Detail
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
getDefaultClassLoader
private static java.lang.ClassLoader getDefaultClassLoader()
-
getAnyWorkQueue
public WorkQueue getAnyWorkQueue()
Description copied from interface:ThreadPool
This method will return any instance of the WorkQueue. If the ThreadPool instance only services one WorkQueue then that WorkQueue instance will be returned. If there are more than one WorkQueues serviced by this ThreadPool, then this method would return a WorkQueue based on the implementation of the class that implements this interface. For PE 8.0 we would return a WorkQueue in a roundrobin fashion everytime this method is called. In the future we could allow pluggability of Policy objects for this.- Specified by:
getAnyWorkQueue
in interfaceThreadPool
-
getWorkQueue
public WorkQueue getWorkQueue(int queueId) throws NoSuchWorkQueueException
Description copied from interface:ThreadPool
This method will return an instance of the of the WorkQueue given a queueId. This will be useful in situations where there are more than one WorkQueues managed by the ThreadPool and the user of the ThreadPool wants to always use the same WorkQueue for doing the Work. If the number of WorkQueues in the ThreadPool are 10, then queueIds will go from 0-9- Specified by:
getWorkQueue
in interfaceThreadPool
- Throws:
NoSuchWorkQueueException
- thrown when queueId passed is invalid
-
createWorkerThreadHelper
private java.lang.Thread createWorkerThreadHelper(java.lang.String name)
-
createWorkerThread
void createWorkerThread()
To be called from the WorkQueue to create worker threads when none available.
-
minimumNumberOfThreads
public int minimumNumberOfThreads()
Description copied from interface:ThreadPool
This method will return the minimum number of threads maintained by the threadpool.- Specified by:
minimumNumberOfThreads
in interfaceThreadPool
-
maximumNumberOfThreads
public int maximumNumberOfThreads()
Description copied from interface:ThreadPool
This method will return the maximum number of threads in the threadpool at any point in time, for the life of the threadpool- Specified by:
maximumNumberOfThreads
in interfaceThreadPool
-
idleTimeoutForThreads
public long idleTimeoutForThreads()
Description copied from interface:ThreadPool
This method will return the time in milliseconds when idle threads in the threadpool are removed.- Specified by:
idleTimeoutForThreads
in interfaceThreadPool
-
currentNumberOfThreads
@ManagedAttribute @Description("The current number of threads") public int currentNumberOfThreads()
Description copied from interface:ThreadPool
This method will return the current number of threads in the threadpool. This method returns a value which is not synchronized.- Specified by:
currentNumberOfThreads
in interfaceThreadPool
-
decrementCurrentNumberOfThreads
void decrementCurrentNumberOfThreads()
-
incrementCurrentNumberOfThreads
void incrementCurrentNumberOfThreads()
-
numberOfAvailableThreads
@ManagedAttribute @Description("The number of available threads in this ThreadPool") public int numberOfAvailableThreads()
Description copied from interface:ThreadPool
This method will return the number of available threads in the threadpool which are waiting for work. This method returns a value which is not synchronized.- Specified by:
numberOfAvailableThreads
in interfaceThreadPool
-
numberOfBusyThreads
@ManagedAttribute @Description("The number of threads busy processing work in this ThreadPool") public int numberOfBusyThreads()
Description copied from interface:ThreadPool
This method will return the number of busy threads in the threadpool This method returns a value which is not synchronized.- Specified by:
numberOfBusyThreads
in interfaceThreadPool
-
averageWorkCompletionTime
@ManagedAttribute @Description("The average time needed to complete a work item") public long averageWorkCompletionTime()
Description copied from interface:ThreadPool
This method returns the average elapsed time taken to complete a Work item.- Specified by:
averageWorkCompletionTime
in interfaceThreadPool
-
currentProcessedCount
@ManagedAttribute @Description("The number of work items processed") public long currentProcessedCount()
Description copied from interface:ThreadPool
This method returns the number of Work items processed by the threadpool- Specified by:
currentProcessedCount
in interfaceThreadPool
-
getName
@NameValue public java.lang.String getName()
Description copied from interface:ThreadPool
This method will return the name of the threadpool.- Specified by:
getName
in interfaceThreadPool
-
numberOfWorkQueues
public int numberOfWorkQueues()
This method will return the number of WorkQueues serviced by the threadpool.- Specified by:
numberOfWorkQueues
in interfaceThreadPool
-
getUniqueThreadId
private static int getUniqueThreadId()
-
decrementNumberOfAvailableThreads
void decrementNumberOfAvailableThreads()
This method will decrement the number of available threads in the threadpool which are waiting for work. Called from WorkQueueImpl.requestWork()
-
incrementNumberOfAvailableThreads
void incrementNumberOfAvailableThreads()
This method will increment the number of available threads in the threadpool which are waiting for work. Called from WorkQueueImpl.requestWork()
-
-