windows:XP
memcached版本:memcached-1.2.1-win32
java client版本:java_memcached-release_1.6public class testMemCached
{
// 创建全局的唯一实例
protected static MemCachedClient mcc = new MemCachedClient();
protected static testMemCached memCached = new testMemCached();
// 设置与缓存服务器的连接池
static {
// 服务器列表和其权重
String[] servers = {"127.0.0.1:11211"};
Integer[] weights = {3};
// 获取socke连接池的实例对象
SockIOPool pool = SockIOPool.getInstance();
// 设置服务器信息
pool.setServers( servers );
pool.setWeights( weights );
// 设置初始连接数、最小和最大连接数以及最大处理时间
pool.setInitConn( 5 );
pool.setMinConn( 5 );
pool.setMaxConn( 250 );
pool.setMaxIdle( 1000 * 60 * 60 * 6 );
// 设置主线程的睡眠时间
pool.setMaintSleep( 30 );
// 设置TCP的参数,连接超时等
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setSocketConnectTO( 0 );
// 初始化连接池
pool.initialize();
// 压缩设置,超过指定大小(单位为K)的数据都会被压缩
mcc.setCompressEnable( true );
mcc.setCompressThreshold( 64 * 1024 );
} protected testMemCached()
{} public static testMemCached getInstance()
{
return memCached;
}
public boolean add(String key, Object value)
{
return mcc.add(key, value);
}
public boolean add(String key, Object value, Date expiry)
{
return mcc.add(key, value, expiry);
}
public boolean replace(String key, Object value)
{
return mcc.replace(key, value);
}
public boolean replace(String key, Object value, Date expiry)
{
return mcc.replace(key, value, expiry);
}
public Object get(String key)
{
return mcc.get(key);
}
public boolean flushAll()
{
return mcc.flushAll();
}
public static void main(String[] args)
{
testMemCached cache = testMemCached.getInstance();
cache.flushAll();
for(int i=0; i<50000;i++){
cache.add(i+"", "test");
} String s = cache.get("0").toString();
System.out.println(s);
}
}1.输出:com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ data successfully stored for key: 49998
2.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - Storing with native handler...
3.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ memcache cmd (result code): add 49999 0 0 5
4. (STORED)
5.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ data successfully stored for key: 49999
6.Exception in thread "main" java.lang.NullPointerException
7. at utils.cache.testMemCached.main(testMemCached.java:90)
memcached启动语句:memcached.exe -l 127.0.0.1 -m 128 -d start
如果我只写入500条记录再读,是没有问题的,但是超过5000条记录就会出现空指针异常了。
请问是哪里出问题了?
memcached版本:memcached-1.2.1-win32
java client版本:java_memcached-release_1.6public class testMemCached
{
// 创建全局的唯一实例
protected static MemCachedClient mcc = new MemCachedClient();
protected static testMemCached memCached = new testMemCached();
// 设置与缓存服务器的连接池
static {
// 服务器列表和其权重
String[] servers = {"127.0.0.1:11211"};
Integer[] weights = {3};
// 获取socke连接池的实例对象
SockIOPool pool = SockIOPool.getInstance();
// 设置服务器信息
pool.setServers( servers );
pool.setWeights( weights );
// 设置初始连接数、最小和最大连接数以及最大处理时间
pool.setInitConn( 5 );
pool.setMinConn( 5 );
pool.setMaxConn( 250 );
pool.setMaxIdle( 1000 * 60 * 60 * 6 );
// 设置主线程的睡眠时间
pool.setMaintSleep( 30 );
// 设置TCP的参数,连接超时等
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setSocketConnectTO( 0 );
// 初始化连接池
pool.initialize();
// 压缩设置,超过指定大小(单位为K)的数据都会被压缩
mcc.setCompressEnable( true );
mcc.setCompressThreshold( 64 * 1024 );
} protected testMemCached()
{} public static testMemCached getInstance()
{
return memCached;
}
public boolean add(String key, Object value)
{
return mcc.add(key, value);
}
public boolean add(String key, Object value, Date expiry)
{
return mcc.add(key, value, expiry);
}
public boolean replace(String key, Object value)
{
return mcc.replace(key, value);
}
public boolean replace(String key, Object value, Date expiry)
{
return mcc.replace(key, value, expiry);
}
public Object get(String key)
{
return mcc.get(key);
}
public boolean flushAll()
{
return mcc.flushAll();
}
public static void main(String[] args)
{
testMemCached cache = testMemCached.getInstance();
cache.flushAll();
for(int i=0; i<50000;i++){
cache.add(i+"", "test");
} String s = cache.get("0").toString();
System.out.println(s);
}
}1.输出:com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ data successfully stored for key: 49998
2.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - Storing with native handler...
3.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ memcache cmd (result code): add 49999 0 0 5
4. (STORED)
5.com.danga.MemCached.MemCachedClient Sun Jan 08 14:42:19 CST 2012 - ++++ data successfully stored for key: 49999
6.Exception in thread "main" java.lang.NullPointerException
7. at utils.cache.testMemCached.main(testMemCached.java:90)
memcached启动语句:memcached.exe -l 127.0.0.1 -m 128 -d start
如果我只写入500条记录再读,是没有问题的,但是超过5000条记录就会出现空指针异常了。
请问是哪里出问题了?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货