在SockIOPool中,有一个类:MaintThread
是Pool的自我维护的线程类。
这个类的使用,看代码是要自己创建一个实例,输入SockIOPool对象进去进行运转;
---------------------------------------------------------------------------------------------------------------------------
在最新的2.6.1版本中,没有看到有维护线程的启动,在2.0版本,在初始化的时候,维护线程就启动了:
/**
* Initializes the pool.
*/
public void initialize() {
synchronized( this ) {
// check to see if already initialized
if ( initialized
&& ( buckets != null || consistentBuckets != null )
&& ( availPool != null )
&& ( busyPool != null ) ) {
log.error( "++++ trying to initialize an already initialized pool" );
return;
}
// pools
availPool = new HashMap<String,Map<SockIO,Long>>( servers.length * initConn );
busyPool = new HashMap<String,Map<SockIO,Long>>( servers.length * initConn );
deadPool = new IdentityHashMap<SockIO,Integer>();
hostDeadDur = new HashMap<String,Long>();
hostDead = new HashMap<String,Date>();
createShift = new HashMap<String,Integer>();
maxCreate = (poolMultiplier > minConn) ? minConn : minConn / poolMultiplier; // only create up to maxCreate connections at once
log.debug( "++++ initializing pool with following settings:" );
log.debug( "++++ initial size: " + initConn );
log.debug( "++++ min spare : " + minConn );
log.debug( "++++ max spare : " + maxConn );
// if servers is not set, or it empty, then
// throw a runtime exception
if ( servers == null || servers.length <= 0 ) {
log.error( "++++ trying to initialize with no servers" );
throw new IllegalStateException( "++++ trying to initialize with no servers" );
}
// initalize our internal hashing structures
if ( this.hashingAlg == CONSISTENT_HASH )
populateConsistentBuckets();
else
populateBuckets();
// mark pool as initialized
this.initialized = true;
// start maint thread
if ( this.maintSleep > 0 )
this.startMaintThread();
}
}
在最后,如果设置的维护时间大于0,就会启动维护线程