V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
teemoer
V2EX  ›  Java

Java 數據庫連接池問題?或者該怎麼提問才好?

  •  1
     
  •   teemoer · 2017-07-10 04:00:30 +08:00 · 3752 次点击
    这是一个创建于 2696 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天寫程式的時候遇到一個問題, A.操作從數據庫獲取一條記錄, B.緊接著下一行代碼是向某服務器發送 post 請求 C.但是某種條件下可能出現對方服務器一直不回覆,導致程序一直卡在等待 post 的 response(為什麼不超時異常?我也很無奈啊) D.這種 情況下,導致 A 操作的連接池一直未釋放,最終在 druid 配置的 removeAbandoned timeout 內 maxActive 達到峰值,造成其他 dao 層一直等待連接池釋放. 從而導致程式卡死或者 500 這種情況那位大佬遇到過,怎麼處理?

    B 操作所依賴的數據必須來自 A ,而且 B 操作完畢的返回 post 數據也需要馬上使用到. 求解.

    下面貼異常信息,com.jh.pay 是我自己程序的 package,ctrl+F 可快速尋見:

    
    11:10:29 ERROR c.alibaba.druid.pool.DruidDataSource[2189] abandon connection, owner thread: http-nio-9011-exec-513, connected at : 1499308823002, open stackTrace
    	at java.lang.Thread.getStackTrace(Thread.java:1556)
    	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1068)
    	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
    	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:662)
    	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
    	at com.alibaba.druid.filter.logging.LogFilter.dataSource_getConnection(LogFilter.java:831)
    	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
    	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:992)
    	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:984)
    	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:103)
    	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    	at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:225)
    	at com.sun.proxy.$Proxy28.setReadOnly(Unknown Source)
    	at org.springframework.jdbc.datasource.DataSourceUtils.prepareConnectionForTransaction(DataSourceUtils.java:155)
    	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:178)
    	at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:430)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    	at com.sun.proxy.$Proxy52.findAll(Unknown Source)
    	at com.jh.pay.service.impl.RechargeDetailServiceImpl.findByOrderNumber(RechargeDetailServiceImpl.java:111)
    	at com.jh.pay.controller.WxPayController.payMoney(WxPayController.java:210)
    	at sun.reflect.GeneratedMethodAccessor207.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:65)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
    	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:745)
    ownerThread current state is RUNNABLE, current stackTrace
    	at java.net.SocketInputStream.socketRead0(Native Method)
    	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    	at java.net.SocketInputStream.read(SocketInputStream.java:171)
    	at java.net.SocketInputStream.read(SocketInputStream.java:141)
    	at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    	at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
    	at sun.security.ssl.InputRecord.read(InputRecord.java:532)
    	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
    	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
    	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
    	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
    	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
    	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    	at com.jh.pay.wxpay.utils.HttpClientUtil.doPostXML(HttpClientUtil.java:188)
    	at com.jh.pay.wxpay.WxPay.doQrPay(WxPay.java:94)
    	at com.jh.pay.service.impl.PayServiceImpl.wxpay(PayServiceImpl.java:88)
    	at com.jh.pay.controller.WxPayController.payMoney(WxPayController.java:302)
    	at sun.reflect.GeneratedMethodAccessor207.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:65)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
    	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:745)
     
    
    
    
    第 1 条附言  ·  2017-07-10 11:49:11 +08:00

    代碼如下:

    rechargeDetailService.findByOrderNumber(orderNumber); 即為A操作(不知道為什麼連接池就是不釋放)

    payService.wxpay(money, orderNumber, testMerchatConfigId); 為向微信服務器進行POST操作

    
     /**
         * 创建微信订单  并且把微信返回的信息放到session
         */
        @RequestMapping(value = "/pub/wx/payMoney", method = {RequestMethod.GET, RequestMethod.POST})
        public String payMoney(
                @RequestParam("appId") String appId,
                @RequestParam("payMoney") String payMoney,
                @RequestParam("orderNumber") String orderNumber,
                @RequestParam("callBackUrl") String callBackUrl,
                @RequestParam("hrefBackUrl") String hrefBackUrl,
                @RequestParam(value = "payType", required = false, defaultValue = "") String payType,
                @RequestParam("sign") String sign,
                @RequestParam(value = "testMerchatConfigId", required = false) Long testMerchatConfigId,
                HttpServletRequest httpServletRequest,
                Model model) {
    
            //判断该订单是否已经存在
            List<RechargeDetail> rechargeDetailList = rechargeDetailService.findByOrderNumber(orderNumber);
            if (rechargeDetailList.size() > 0) {
                RechargeDetail rechargeDetail = rechargeDetailList.get(0);
                Map map = Maps.newHashMap();
                map.put("code_url", rechargeDetail.getWeChatCodeUrl());
                if (rechargeDetail.getPayType() == PayType.PAY) {
                    model.addAttribute("error", "该订单已经支付过,请勿重复支付 !");
                }
                model.addAttribute("payMap", map);
                model.addAttribute("payNo", orderNumber);
                return "/wx/showEwm";
            }
    
            UserMerchantList userMerchantList = userMerchantListService.findByAppId(appId);
            if (userMerchantList == null) {
                model.addAttribute("error", "签名错误:AppId " + appId + "  不存在!");
                return "/wx/showEwm";
            }
            StringBuilder sb = new StringBuilder("");
      
    
    
    
    第 2 条附言  ·  2017-07-10 11:49:29 +08:00
      sb.append("appId=").append(appId).
                    append("&payMoney=").append(payMoney).
                    append("&orderNumber=").append(orderNumber).
                    append("&callBackUrl=").append(callBackUrl).
                    append("&hrefBackUrl=").append(hrefBackUrl);
    
    
    //        if (StringUtils.isNotBlank(payMoney)) {
    //            sb.append("&payType=").append(payType);
    //        }
            sb.append(userMerchantList.getKey());
            SignatureUtlis signatureUtlis = new SignatureUtlis();
            String result;
            try {
                result = signatureUtlis.signatureCmd5(sb.toString());
            } catch (Exception e) {
                e.printStackTrace();
                model.addAttribute("error", "签名错误:" + e.getMessage());
                return "/wx/showEwm";
            }
            if (!(StringUtils.isNotBlank(result) && result.equals(sign))) {
                model.addAttribute("error", "签名错误!");
                return "/wx/showEwm";
            }
            User user = userService.findByUserNameIfNotExitCreate(orderNumber);
            Double money;
            try {
                money = Double.valueOf(payMoney);
            } catch (NumberFormatException numberFormatEx) {
                model.addAttribute("error", "获取金额失败,金额格式错误:" + payMoney);
                return "/wx/showEwm";
            }
    
    
    第 3 条附言  ·  2017-07-10 11:49:57 +08:00
    
    
    
            RechargeDetail rechargeDetail = new RechargeDetail();
            //设置订单为 未付款
            rechargeDetail.setPayType(PayType.NOT_PAY);
            rechargeDetail.setUser(user);
            rechargeDetail.setCallTotal(0);
            rechargeDetail.setCreateDate(new Date());
            rechargeDetail.setRechargeNo(orderNumber);
            rechargeDetail.setUserAppId(appId);
            rechargeDetail.setCallType(CallType.NO);
            rechargeDetail.setCallBackUrl(callBackUrl);
            rechargeDetail.setHrefBackUrl(hrefBackUrl);
            rechargeDetail.setMoney(money);
            rechargeDetail.setIpAddr(IpAddrUtils.getRemoteAddr(httpServletRequest));
    
            StringBuilder sb2 = new StringBuilder("");
            sb2.append("appId=").append(rechargeDetail.getUserAppId()).
                    append("&orderNumber=").append(rechargeDetail.getRechargeNo()).
                    append("&orderStatus=").append("Yes");
            String resultSignature = "";
            try {
                resultSignature = signatureUtlis.signatureCmd5(sb2.toString() + userMerchantList.getKey());
            } catch (Exception e) {
                e.printStackTrace();
                log.debug("签名错误:" + e.getMessage());
            }
            sb2.append("&sign=").append(resultSignature);
            rechargeDetail.setSignStr(sb2.toString());
    
    
    
    
    第 4 条附言  ·  2017-07-10 11:50:27 +08:00

    //判断是否是私人微信 if (YES.equals(userMerchantList.getIsPerson())) { rechargeDetail.setIsPersonPay(YES); rechargeDetail.setStrMark(getRoamStr(money)); rechargeDetailService.save(rechargeDetail); model.addAttribute("id", userMerchantList.getId()); model.addAttribute("money", money); model.addAttribute("payNo", orderNumber); model.addAttribute("mark", rechargeDetail.getStrMark()); return "/wx/showPersonEwm"; } else { rechargeDetail.setIsPersonPay(NO); //如果是企业微信或者企业支付宝 Map<String, Object> payMap; //如果是微信 if (!"ali".equals(payType)) { try { payMap = payService.wxpay(money, orderNumber, testMerchatConfigId); } catch (WxExceptions wxExceptions) { model.addAttribute("error", wxExceptions.getMessage()); return "/wx/showEwm"; } //二维码 未获取到 if (payMap.get("code_url") == null) { model.addAttribute("error", "充值失败,未获取到微信二维码!" + payMap.get("return_msg") + payMap.get("err_code_des")); return "/wx/error"; }

                rechargeDetail.setWeChatCodeUrl(payMap.get("code_url").toString());
                if (payMap.get("jh_appid") != null) {
                    rechargeDetail.setAppId((String) payMap.get("jh_appid"));
                }
                rechargeDetailService.save(rechargeDetail);
                model.addAttribute("payMap", payMap);
                model.addAttribute("payNo", orderNumber);
                return "/wx/showEwm";
            } else {
    
    第 5 条附言  ·  2017-07-10 11:51:59 +08:00

    第四條附言 忘記 markdown了 請忽略 我重新發佈一次

    
        //判断是否是私人微信
            if (YES.equals(userMerchantList.getIsPerson())) {
                rechargeDetail.setIsPersonPay(YES);
                rechargeDetail.setStrMark(getRoamStr(money));
                rechargeDetailService.save(rechargeDetail);
                model.addAttribute("id", userMerchantList.getId());
                model.addAttribute("money", money);
                model.addAttribute("payNo", orderNumber);
                model.addAttribute("mark", rechargeDetail.getStrMark());
                return "/wx/showPersonEwm";
            } else {
                rechargeDetail.setIsPersonPay(NO);
                //如果是企业微信或者企业支付宝
                Map<String, Object> payMap;
                //如果是微信
                if (!"ali".equals(payType)) {
                    try {
                        payMap = payService.wxpay(money, orderNumber, testMerchatConfigId);
                    } catch (WxExceptions wxExceptions) {
                        model.addAttribute("error", wxExceptions.getMessage());
                        return "/wx/showEwm";
                    }
                    //二维码 未获取到
                    if (payMap.get("code_url") == null) {
                        model.addAttribute("error", "充值失败,未获取到微信二维码!" + payMap.get("return_msg") + payMap.get("err_code_des"));
                        return "/wx/error";
                    }
    
                    rechargeDetail.setWeChatCodeUrl(payMap.get("code_url").toString());
                    if (payMap.get("jh_appid") != null) {
                        rechargeDetail.setAppId((String) payMap.get("jh_appid"));
                    }
                    rechargeDetailService.save(rechargeDetail);
                    model.addAttribute("payMap", payMap);
                    model.addAttribute("payNo", orderNumber);
                    return "/wx/showEwm";
                } else {
    
    
    
    第 6 条附言  ·  2017-07-10 11:52:17 +08:00
    
    
    
                    payMap = payService.aliPay(money, orderNumber, testMerchatConfigId);
                    //二维码 未获取到
                    if (payMap.get("qr_code") == null) {
                        model.addAttribute("error", "充值失败,未获取到支付宝二维码!" + payMap.toString());
                        return "/wx/error";
                    }
                    rechargeDetail.setWeChatCodeUrl(payMap.get("qr_code").toString());
                    if (payMap.get("jh_appid") != null) {
                        rechargeDetail.setAppId((String) payMap.get("jh_appid"));
                    }
                    payMap.put("code_url", payMap.get("qr_code"));
                    rechargeDetailService.save(rechargeDetail);
                    model.addAttribute("payMap", payMap);
                    model.addAttribute("payNo", orderNumber);
                    return "/wx/showEwm";
                }
    
            }
    
        }
    
    
    
    29 条回复    2017-07-24 18:08:04 +08:00
    wenzhoou
        1
    wenzhoou  
       2017-07-10 07:41:42 +08:00 via Android
    B 的锅。post 时候 timeout 和 retry 必须要想到。不然多少的连接池也架不住。
    不过如果业务上能变成异步处理,那就最好了。
    连接数是 tps x 平均响应时间吧。峰值连接数就是 峰值 tps x 峰值响应时间啦。你这峰值响应时间趋于无穷大怎么搞。
    ovear
        2
    ovear  
       2017-07-10 08:45:49 +08:00 via Android   ❤️ 2
    请换简体中文
    sagaxu
        3
    sagaxu  
       2017-07-10 09:21:23 +08:00 via Android
    A 完成的时候就该释放连接了
    wayne1943
        4
    wayne1943  
       2017-07-10 09:31:41 +08:00 via iPhone
    程式?楼主是台湾人?
    xmh51
        5
    xmh51  
       2017-07-10 09:41:19 +08:00
    利用 java FutureTask 类 强制设定超时时间 过了 多少秒 如果拿不到结果,就进行异常处理。
    jalena
        6
    jalena  
       2017-07-10 10:21:51 +08:00
    不贴点代码是最可恶的提问,那么,为啥子不捕获超时这个异常呢?或者设定超时呢~??
    tianshilei1992
        7
    tianshilei1992  
       2017-07-10 10:27:30 +08:00 via iPhone
    @ovear 楼主是台湾人…不是大陆人用繁体字…
    ovear
        8
    ovear  
       2017-07-10 10:31:21 +08:00
    @tianshilei1992 问题是我看了半天也没看懂。。
    a b c 代表的到底是操作,还是不同的服务
    vingz
        9
    vingz  
       2017-07-10 10:38:47 +08:00
    A 和 B 应该是异步隔离,A 操作完成后,把数据发给 B 去处理,A 释放数据库连接;
    B 收到数据后发 post 请求,设置 socket 的读写超时时间,这样一直没有 response 的时候 B 会报错。
    A 和 B 要是多线程,线程之间可以通过消息通信。
    v2orz
        10
    v2orz  
       2017-07-10 10:50:48 +08:00
    发送 post 的 httpClient 或者别的什么,设置合理的超时时间
    顺便,A 操作获取到结果后,数据库连接就应该已经还给连接池了
    teemoer
        11
    teemoer  
    OP
       2017-07-10 11:39:48 +08:00
    @wayne1943 不是 寫習慣了
    teemoer
        12
    teemoer  
    OP
       2017-07-10 11:41:04 +08:00
    @wenzhoou 打算 按照 5 樓說的 使用超時拋出異常,感謝
    teemoer
        13
    teemoer  
    OP
       2017-07-10 11:46:37 +08:00
    @vingc723
    @v2orz

    A 操作 用的 springDataJpa 不知道為什麼 明明查詢完畢 就是不釋放連接池 ,我在樓上 貼上了 代碼


    @sagaxu
    @ovear
    @jalena
    letitbesqzr
        14
    letitbesqzr  
       2017-07-10 12:32:53 +08:00
    手动管理事务
    hcymk2
        15
    hcymk2  
       2017-07-10 12:37:27 +08:00
    teemoer
        17
    teemoer  
    OP
       2017-07-10 14:25:32 +08:00
    @letitbesqzr 順其自然洋 XD = = 洋哥好
    teemoer
        18
    teemoer  
    OP
       2017-07-10 14:26:02 +08:00
    @hcymk2 感謝 我馬上去看看
    zacard
        19
    zacard  
       2017-07-10 14:34:40 +08:00
    这里面问题非常多。。。。
    有个原则:调用外部资源都应该设置超时!
    letitbesqzr
        20
    letitbesqzr  
       2017-07-10 16:15:17 +08:00
    偉滒沵恏 沵看莪哋焱暒妏恏看嬤
    letitbesqzr
        21
    letitbesqzr  
       2017-07-10 16:15:52 +08:00
    ︶ㄣ`妳怼我绝情,蹴別怪我怼妳嫵情~
    letitbesqzr
        22
    letitbesqzr  
       2017-07-10 16:17:27 +08:00
    ┈┾分吥請愛與吥愛,是莪蕞夶的悲哀 ̄*
    LavenderLee
        23
    LavenderLee  
       2017-07-10 16:18:13 +08:00   ❤️ 1
    ヤ我嬒鞍瀞锝走掉,芣咑яáδρì
    tulongtou
        24
    tulongtou  
       2017-07-10 17:00:13 +08:00 via iPhone
    @wayne1943 我感觉是假台湾人,台湾不是叫伺服器嘛
    tianshilei1992
        25
    tianshilei1992  
       2017-07-10 17:34:27 +08:00 via iPhone
    @ovear 下面被光速打脸😂并不是台湾人 哈哈
    roooz
        26
    roooz  
       2017-07-10 19:59:57 +08:00
    这坛子灌水的是越来越多了
    teemoer
        27
    teemoer  
    OP
       2017-07-11 22:51:46 +08:00 via iPhone
    @roooz 何来灌水一说
    EXE
        28
    EXE  
       2017-07-12 08:47:23 +08:00
    这么喜欢用繁体,注释为啥不用
    shuangmu
        29
    shuangmu  
       2017-07-24 18:08:04 +08:00
    繁体看的我眼睛累
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2764 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:22 · PVG 08:22 · LAX 16:22 · JFK 19:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.