版本:gwhalin-Memcached-Java-Client-release_2.6.1-0-gab2cc7e
在memcached使用中:
static { String[] serverlist = { "cache0.server.com:12345", "cache1.server.com:12345" }; SockIOPool pool = SockIOPool.getInstance(); pool.setServers(serverlist); pool.initialize(); }
最后需要对pool进行initialize();其实就是调用的SchoonerSockIOPool的initialize:
public void initialize() { schoonerSockIOPool.initialize(); }
而在SchoonerSockIOPool初始化中,
public void initialize() { initDeadLock.lock(); try { // 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"); } // pools socketPool = new HashMap<String, GenericObjectPool>(servers.length); hostDead = new ConcurrentHashMap<String, Date>(); hostDeadDur = new ConcurrentHashMap<String, Long>(); // only create up to maxCreate connections at once // initalize our internal hashing structures if (this.hashingAlg == CONSISTENT_HASH) populateConsistentBuckets(); else populateBuckets(); // mark pool as initialized this.initialized = true; } finally { initDeadLock.unlock(); } }
在初始化最后设置了this.initialized = true
如果拿到的是同一个SchoonerSockIOPool,就会又一次初始化,这个算不算一个bug?
--------------------
在自己编程序的时候,把pool的设置集中在一个地方,只进行一次,这样应该就不会有什么问题了。
下面就是在MemCachedClient 中,使用这些Pool了