【memcached】initialize是不是一个问题?

版本: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了

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值