Memcached+Java报错
关注:232 答案:1 mip版
解决时间 2021-02-05 00:15
提问者终不敌时光
2021-02-04 16:35
public class Test {
private static final String POOL_NAME="mysql";
protected static MemCachedClient mcc;
static {
//设置缓存服务器列表,当使用分布式缓存的时,可以指定多个缓存服务器
String[] servers =
{
"127.0.0.1:3306"
};
//与服务器列表中对应的各服务器的权重
Integer[] weights = {3};
//创建Socked连接池
SockIOPool pool = SockIOPool.getInstance(POOL_NAME);
//向连接池设定服务器和权重
pool.setServers( servers );
pool.setWeights( weights );
//连接池参数
pool.setInitConn( 5 );
pool.setMinConn( 5 );
pool.setMaxConn( 250 );
pool.setMaxIdle( 1000 * 60 * 60 * 6 );
// set the sleep for the maint thread
// it will wake up every x seconds and
// maintain the pool size
pool.setMaintSleep( 30 );
// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don't set a connect timeout
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setSocketConnectTO( 0 );
// initialize the connection pool
pool.initialize();
// lets set some compression on for the client
// compress anything larger than 64k
mcc=new MemCachedClient(POOL_NAME);
mcc.setCompressEnable( true );
mcc.setCompressThreshold( 64 * 1024 );
}
public static void main(String[] args) throws Exception{
mcc.set("msg","Hello,world!",new Date(System.currentTimeMillis()+1300));
Thread.sleep(500);
System.out.println(mcc.get("msg"));
}
}
异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsupportedOperationException
at com.danga.MemCached.MemCachedClient.setCompressEnable(Unknown Source)
at spring.unif.tool.Test.(Test.java:46)
最佳答案
二级知识专家千里故人稀
2021-02-04 17:18
正好 我刚做了一个 要源码吗?
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
→点此我要举报以上信息!←
推荐资讯
大家都在看