Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2561755
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Java

2014-10-10 16:58:53

使用jedispool发生以下异常

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe
        at redis.clients.jedis.Connection.flush(Connection.java:70)
        at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:173)
        at redis.clients.jedis.Jedis.set(Jedis.java:54)
        at com.gfan.user.adapt.ApiController.register(ApiController.java:131)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:31)
        at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:223)
        at redis.clients.jedis.Connection.flush(Connection.java:68)
        ... 42 more

solution

在jedis使用完后需要还回到连接池 参考代码:
        JedisPool pool = JedisFactory.getInstance().getJedisPool();
        Jedis jedis = pool.getResource();
        try{
            String numstr = jedis.get(Config.EMAILTIMES + validateId);
            int num = 0;
            if (numstr != null && Integer.parseInt(numstr) >= 3) {
                result.put("code", 1);
                result.put("message", "已发送三次");
                return mapToJson(result);
            } else {
                jedis.incr(Config.EMAILTIMES + validateId);
            }

            String preRegisterKey1 = Config.REGISTERCACHE + validateId;
             email = jedis.hget(preRegisterKey1,Config.USERNAME);
             regDate = jedis.hget(preRegisterKey1,Config.REG_DATE);
             expireDate = jedis.hget(preRegisterKey1,Config.EMAIL_VERIFY_URL_EXPIRE);
             long now = System.currentTimeMillis() / 1000;
 
            sendDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date(System.currentTimeMillis()));
             veryUrl = jedis.hget(preRegisterKey1,Config.EMAIL_VERIFY_URL);
            pool.returnResource(jedis);
        }catch(Exception e){
            if(null != pool && null != jedis)
                pool.returnBrokenResource(jedis);
            log.error("从缓存中读取数据时,发生异常:"+e.getMessage(),e);
            e.printStackTrace();
        }
阅读(11230) | 评论(0) | 转发(0) |
0

上一篇:Hydra

下一篇:maven找不到dependency

给主人留下些什么吧!~~