* @param config
* @return A ThreadPoll wrapper
*/
private ThreadPool createPool( PoolConfiguration config )
{
PooledExecutor pool = null;
Channel queue = null;
if ( config.isUseBoundary() )
{
if ( log.isDebugEnabled() )
{
log.debug( "Creating a Bounded Buffer to use for the pool" );
}
queue = new BoundedBuffer( config.getBoundarySize() );
pool = new PooledExecutor( queue, config.getMaximumPoolSize() );
pool.setThreadFactory( new MyThreadFactory() );
}
else
{
if ( log.isDebugEnabled() )
{
log.debug( "Creating a non bounded Linked Queue to use for the pool" );
}
queue = new LinkedQueue();
pool = new PooledExecutor( queue, config.getMaximumPoolSize() );
}
pool.setMinimumPoolSize( config.getMinimumPoolSize() );
pool.setKeepAliveTime( config.getKeepAliveTime() );
// when blocked policy
if ( config.getWhenBlockedPolicy().equals( IPoolConfiguration.POLICY_ABORT ) )
{
pool.abortWhenBlocked();
}
else if ( config.getWhenBlockedPolicy().equals( IPoolConfiguration.POLICY_RUN ) )
{
pool.runWhenBlocked();
}
else if ( config.getWhenBlockedPolicy().equals( IPoolConfiguration.POLICY_WAIT ) )
{
pool.waitWhenBlocked();
}
else if ( config.getWhenBlockedPolicy().equals( IPoolConfiguration.POLICY_ABORT ) )
{
pool.abortWhenBlocked();
}
else if ( config.getWhenBlockedPolicy().equals( IPoolConfiguration.POLICY_DISCARDOLDEST ) )
{
pool.discardOldestWhenBlocked();
}
pool.createThreads( config.getStartUpSize() );
return new ThreadPool( pool, queue );
}