public abstract class BaseThreadPool extends java.lang.Object implements ThreadPool
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseThreadPool.SessionBuffer |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_KEEP_ALIVE_TIME
Default keep-alive time of thread pool (1 min).
|
static int |
DEFAULT_MAXIMUM_POOL_SIZE
Default maximum size of thread pool (2G).
|
Constructor and Description |
---|
BaseThreadPool(java.lang.String threadNamePrefix)
Creates a new instance with default thread pool settings.
|
Modifier and Type | Method and Description |
---|---|
protected BaseThreadPool.SessionBuffer |
fetchSessionBuffer(Queue unfetchedSessionBuffers)
Implement this method to fetch (or pop) a
BaseThreadPool.SessionBuffer from
the given unfetchedSessionBuffers. |
protected void |
fireEvent(java.lang.Object nextFilter,
Session session,
EventType type,
java.lang.Object data) |
int |
getKeepAliveTime()
Returns the keep-alive time until the thread suicides after it became
idle (milliseconds unit).
|
int |
getMaximumPoolSize()
Returns the maximum size of the thread pool.
|
int |
getPoolSize()
Returns the number of threads in the thread pool.
|
java.lang.String |
getThreadNamePrefix() |
protected abstract void |
processEvent(java.lang.Object nextFilter,
Session session,
EventType type,
java.lang.Object data)
Implement this method to forward events to nextFilter.
|
void |
setKeepAliveTime(int keepAliveTime)
Sets the keep-alive time until the thread suicides after it became idle
(milliseconds unit).
|
void |
setMaximumPoolSize(int maximumPoolSize)
Sets the maximum size of the thread pool.
|
void |
start()
Starts thread pool threads and starts forwarding events to them.
|
void |
stop()
Stops all thread pool threads.
|
public static final int DEFAULT_MAXIMUM_POOL_SIZE
public static final int DEFAULT_KEEP_ALIVE_TIME
public BaseThreadPool(java.lang.String threadNamePrefix)
start()
method to start threads actually.threadNamePrefix
- the prefix of the thread names this pool will create.public java.lang.String getThreadNamePrefix()
public int getPoolSize()
ThreadPool
getPoolSize
in interface ThreadPool
public int getMaximumPoolSize()
ThreadPool
getMaximumPoolSize
in interface ThreadPool
public int getKeepAliveTime()
ThreadPool
getKeepAliveTime
in interface ThreadPool
public void setMaximumPoolSize(int maximumPoolSize)
ThreadPool
setMaximumPoolSize
in interface ThreadPool
public void setKeepAliveTime(int keepAliveTime)
ThreadPool
setKeepAliveTime
in interface ThreadPool
public void start()
ThreadPool
start
in interface ThreadPool
public void stop()
ThreadPool
stop
in interface ThreadPool
protected void fireEvent(java.lang.Object nextFilter, Session session, EventType type, java.lang.Object data)
protected abstract void processEvent(java.lang.Object nextFilter, Session session, EventType type, java.lang.Object data)
protected BaseThreadPool.SessionBuffer fetchSessionBuffer(Queue unfetchedSessionBuffers)
BaseThreadPool.SessionBuffer
from
the given unfetchedSessionBuffers. The default implementation
simply pops the buffer from it. You could prioritize the fetch order.BaseThreadPool.SessionBuffer