2015-07-19 56 views
0
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運行該代碼,並同時獲得的SchoonerSockIOPool比如,它是扔invocationTarget異常的內存緩存中InitMemServer方法設置對象,在上面的代碼片斷。如何在java web應用程序中特別使用在tomcat上運行的Struts 2中的memcached客戶端?

+0

堆棧跟蹤是否可用?然後發佈問題。 –

回答

0
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. 
相關問題