![](/img/trans.png)
[英]How do I find hotspots in a java web application (running in Tomcat)?
[英]How to use memcached client in java web application specially in Struts 2 which is running on tomcat?
public class MemCacheClientInit {
static MemcachedClient mcc = null;
static String ipAdderss = "127.0.0.1";
static int port = 11211;
public static boolean isMemCacheInit = false;
public static MemcachedClient getInstance() {
if (mcc == null) {
try {
isMemCacheInit = initMemServer();
mcc = new MemcachedClient(new InetSocketAddress(ipAdderss, port));
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return mcc;
}
private static boolean initMemServer() {
try {
String[] servers = {"localhost:11211",};
Integer[] weights = {1};
SchoonerSockIOPool pool = SchoonerSockIOPool.getInstance();
pool.setServers(servers);
pool.setWeights(weights);
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);
pool.initialize();
pool.setHashingAlg(SchoonerSockIOPool.NEW_COMPAT_HASH);
return true;
}
catch (Exception ex) {
return false;
}
}
}
我直接从我的DAO运行此代码,并在InitMemServer
方法的上面的代码片段中的Memcache中设置对象,同时获取SchoonerSockIOPool
实例,它InitMemServer
invocationTarget
Exception。
I got the answer it was in the pom.xml
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.1</version>
<scope>provided</scope>
</dependency>
I have given scope as provided that should be compile.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.