这个是异常信息2011-09-27 14:16:03|INFO|com.huawei.internet.appserver.util.soap.DSHttpClient|auth|Enter into ServiceAuth:getUserLoginInfoFromCache().
2011-09-27 14:16:03|DEBUG|com.huawei.internet.appserver.util.soap.DSHttpClient|Util|ServiceAuth.get(key).key is :10086000000000704_1_lifanghua10_0011
2011-09-27 14:16:03|INFO|com.huawei.internet.appserver.util.soap.DSHttpClient|memcached|enter the MyMemcached.get,key is : 10086000000000704_1_lifanghua10_0011
2011-9-27 14:16:03 com.schooner.MemCached.AscIIClient get
涓ラ噸: ++++ exception thrown while trying to get object from cache for key: 10086000000000704_1_lifanghua10_0011
2011-9-27 14:16:03 com.schooner.MemCached.AscIIClient get
涓ラ噸: null
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:474)
at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:208)
at com.schooner.MemCached.SockInputStream.read(SockInputStream.java:110)
at com.schooner.MemCached.AscIIClient.get(AscIIClient.java:702)
at com.schooner.MemCached.AscIIClient.get(AscIIClient.java:609)
at com.schooner.MemCached.AscIIClient.get(AscIIClient.java:605)
at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:911)
at com.huawei.internet.appserver.cache.MemCached.get(MemCached.java:220)
at com.huawei.internet.appserver.common.auth.ServiceAuth.getUserLoginInfoFromCache(Unknown Source)
at com.huawei.internet.appserver.common.auth.ServiceAuth.getUserLoginInfo(Unknown Source)
at com.huawei.internet.appserver.util.tool.CheckTool.checkSid(Unknown Source)
at com.huawei.internet.atphone.action.ActionServiceImpl.installApk(Unknown Source)
at sun.reflect.GeneratedMethodAccessor187.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:153)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:87)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:97)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:461)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:148)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:889)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:732)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2262)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
2011-09-27 14:16:03|INFO|com.huawei.internet.appserver.util.soap.DSHttpClient|memcached|exit the MyMemcached.get,the values is : null
2011-09-27 14:16:03|INFO|com.huawei.internet.appserver.util.soap.DSHttpClient|auth|Exit from ServiceAuth:getUserLoginInfoFromCache().这个是我的代码public final class MemCached
{
    /**
     * 日志信息
     */
    private static Log logger = LogFactory.getLog(MemCached.class);
    
    /**
     * 初始化client
     */
    private static MemCachedClient mcc = new MemCachedClient();
    
    /**
     * 初始化本地管理
     */
    private static MemCached manager = new MemCached();
    
    /**
     * 连接池
     */
    private static SockIOPool pool = null;
    
    /**
     * 单例
     */
    private MemCached()
    {
        
    }
    
    /**
     * 初始化SockIOPool
     */
    public static void init()
    {
        //记录进口日志
        logger.printRunLog("memcached",
            "ento the MyMemcached.init",
            Contants.INFO);
        
        //获取memcached的ip地址
        String ipAddr = SystemConfig.getValue(Contants.MEM_ADDRESS);
        //判断是否为空,不是则去掉前后空格
        ipAddr = (null == ipAddr || "".equals(ipAddr)) ? ipAddr : ipAddr.trim();
        
        //获取memcached的端口
        String memPort = SystemConfig.getValue(Contants.MEM_PORT);
        
        //判断端口是否为空,不是则去掉前后空格
        memPort =
            (null == memPort || "".equals(memPort)) ? memPort : memPort.trim();
        
        //memcached地址和端口
        String address = ipAddr + Contants.COLON + memPort;
        
        //设置服务器地址
        String[] servers = {address };
        
        logger.printRunLog("memcached", "the mem address is :"
            + address, Contants.DEBUG);
        
        //设置服务器权重
        Integer[] weights = {NumContants.THREE.getValue() };
        
        pool = SockIOPool.getInstance();
        
        //设置服务器信息
        pool.setServers(servers);
        pool.setWeights(weights);
        
        //设置初始连接数,最大和最小连接数以及最大处理时间
        pool.setInitConn(Integer.parseInt(SystemConfig.getValue(Contants.MEMINITCONNT)));
        pool.setMinConn(Integer.parseInt(SystemConfig.getValue(Contants.MEMMINCONN)));
        pool.setMaxConn(Integer.parseInt(SystemConfig.getValue(Contants.MEMMAXCONN)));
        pool.setMaxIdle(Integer.parseInt(SystemConfig.getValue(Contants.MEMMAXIDLE)));
        
        //socket连接的超时时间,下面设置表示连接不超时,即一直保持连接状态
        pool.setSocketConnectTO(Integer.parseInt(SystemConfig.getValue(Contants.MEMSOCKETCTO)));
        
        //通讯的超时时间
        pool.setSocketTO(Integer.parseInt(SystemConfig.getValue(Contants.MEMSOCKETTO)));
        
        //socket单次任务的最大时间,超过这个时间socket会被强行中断掉(当前任务失败)
        pool.setMaxBusyTime(Integer.parseInt(SystemConfig.getValue(Contants.MEMMAXBUSYTIME)));
        
        //设置主线程睡眠时间
        pool.setMaintSleep(Integer.parseInt(SystemConfig.getValue(Contants.MEMMAINSLEEP)));
        
        //设置连接失败恢复开关
        pool.setFailback(Boolean.parseBoolean(SystemConfig.getValue(Contants.MEMFAILBACK)));
        
        //设置容错开关 设置为TRUE,当当前socket不可用时,程序会自动查找可用连接并返回,否则返回NULL
        pool.setFailover(Boolean.parseBoolean(SystemConfig.getValue(Contants.MEMFAILOVER)));
        
        //设置连接心跳监测开关。 
        //        pool.setAliveCheck(Boolean.parseBoolean(SystemConfig.getValue(Contants.MEMALIVECHECK)));
        
        //设置是否使用Nagle算法
        pool.setNagle(Boolean.parseBoolean(SystemConfig.getValue(Contants.MEMNAGLE)));
        
        //设置缓冲区大小
        pool.setBufferSize(256 * 8 * 1024);
        
        //初始化连接池
        pool.initialize();
        
        //记录出口日志
        logger.printRunLog("memcached",
            "exit the MyMemcached.init",
            Contants.INFO);
    }
    
    /**
     * 获取单例
     * @return MyMemcached
     */
    public static MemCached getInstance()
    {
        return manager;
    }  
    /**
     * 根据key获取信息
     * @param key key
     * @return object
     */
    public Object get(String key)
    {
        //记录进口日志
        logger.printRunLog("memcached",
            "enter the MyMemcached.get,key is : " + key,
            Contants.INFO);
        
        Object result = mcc.get(key);
        
        //记录出口日志
        logger.printRunLog("memcached",
            "exit the MyMemcached.get,the values is : " + result,
            Contants.INFO);
        
        return result;
    }
}

解决方案 »

  1. 补充一点,就是每次重启memcached之后的第一次请求就会抛这个异常.
    没人懂吗?
      

  2. 不太懂http://my.oschina.net/javagg/blog/3319?from=rss
      

  3. lz用的什麽客戶端,我用的是 com.danga.MemCached.MemCachedClient ,没出现过这样情况。有可能是你的memcache客户端有bug
      

  4. 帮着顶一下吧,以前用过memcached没出现过这种问题,会不会是网络的问题
      

  5. 你的代码里pool和mcc没有半毛钱关系啊,初始化MemCachedClient的时候,程序根本不知道服务器在哪儿,设置的参数要作为MemCachedClient的构造函数的参数传进去才有用,具体的要查api!
      

类似问题 »