错误504白色在执行程序服务中运行invokeAll

时间:2018-04-18 15:56:57

标签: java multithreading weblogic java-7 executorservice

我正在执行大约500-1000的批量数据库操作(每个操作大约30毫秒处理),所以我选择执行服务。

当我处理了100条记录时,它已正确执行。当我处理了500条记录时,我收到了错误504,但由于我无法显示警告消息,所以记录处理后台。

你可以帮忙解决这个问题吗?

 ThreadPoolExecutor executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
 List<Employee> futureList = new ArrayList<Employee>();

for(int i = 0; i < empList.length; i++){
    String empNo = empList\[i\].split("\\|")\[0\];
    EmployeeSave employeeSave = new EmployeeSave(empNo);//Callable Class
    futureList.add(employeeSave);   

}

List<Future<Boolean>> resultList = executorService.invokeAll(futureList);  
List<Boolean> result= new ArrayList<>();
for(Future<Boolean> future : resultList)
 {
    try
    {
        result.add(future.get());
    }
        catch (InterruptedException | ExecutionException e)
    {
     e.printStackTrace();
    }finally{
         //shut down the executor service now
          executorService.shutdown();
         try {
            if (!executorService.awaitTermination(800, TimeUnit.MILLISECONDS)) {
                   executorService.shutdownNow();
            } 
            } catch (InterruptedException e) {
                   executorService.shutdownNow();
            }
       }
}

java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
    at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
    at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)
    at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:427)
    at weblogic.servlet.internal.CharsetChunkOutput.flush(CharsetChunkOutput.java:298)
    at weblogic.servlet.internal.ChunkOutput$2.checkForFlush(ChunkOutput.java:648)
    at weblogic.servlet.internal.CharsetChunkOutput.print(CharsetChunkOutput.java:280)
    at weblogic.servlet.internal.ChunkOutputWrapper.print(ChunkOutputWrapper.java:171)
    at weblogic.servlet.jsp.JspWriterImpl.write(JspWriterImpl.java:259)
    at com.crimsonlogic.trade.common.taglib.TablePrintTag.doEndTag(TablePrintTag.java:868)
    at jsp_servlet._aci._highway._tile.__arrivalcertmesgsearchsummaryview._jspService(__arrivalcertmesgsearchsummaryview.java:611)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:447)
    at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:163)
    at jsp_servlet._aci._highway._screen.__searcharrivalcertmesgscreen._jspService(__searcharrivalcertmesgscreen.java:195)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:447)
    at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:163)
    at jsp_servlet._common._ifx.__popup._jspService(__popup.java:132)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:447)
    at jsp_servlet._pfk.__pfkmain._jspService(__pfkmain.java:532)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:447)
    at com.sns.pfk.servlet.PfkMainServlet.doGet(PfkMainServlet.java:234)
    at com.sns.pfk.servlet.PfkMainServlet.doPost(PfkMainServlet.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:447)
    at com.crimsonlogic.trade.servlet.ITABaseServlet.dispatch(ITABaseServlet.java:569)
    at com.crimsonlogic.trade.common.ifx.servlet.ControllerServlet.doPost(ControllerServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at com.sns.ana.ui.servlet.AuthorisationBaseServlet.service(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:526)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:253)
    at com.crimsonlogic.trade.common.ifx.servlet.ControllerServlet.doForward(ControllerServlet.java:241)
    at com.crimsonlogic.trade.common.ifx.servlet.ControllerServlet.doPost(ControllerServlet.java:131)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at com.sns.ana.ui.servlet.AuthorisationBaseServlet.service(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.crimsonlogic.trade.common.ifx.filter.NAXSSFilter.doFilter(NAXSSFilter.java:66)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.sns.pfk.filter.PFKCSRFLoadSaltFilter.doFilter(PFKCSRFLoadSaltFilter.java:51)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
    at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
    at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)
    at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:427)
    at weblogic.servlet.internal.CharsetChunkOutput.flush(CharsetChunkOutput.java:298)
    at weblogic.servlet.internal.ChunkOutput$2.checkForFlush(ChunkOutput.java:648)
    at weblogic.servlet.internal.CharsetChunkOutput.print(CharsetChunkOutput.java:280)
    at weblogic.servlet.internal.ChunkOutputWrapper.print(ChunkOutputWrapper.java:171)
    at weblogic.servlet.jsp.JspWriterImpl.write(JspWriterImpl.java:259)

enter image description here

1 个答案:

答案 0 :(得分:0)

来自javadoc of ExecutorService class

  

执行给定的任务,返回持有状态的结果列表和结果完成后

这意味着如果列表足够大,执行所有任务可能会使等待的外部系统超时。您可以更快地保存,或者需要更多的超时。

另一种可能的解决方案:实际执行异步计算,不要等待所有任务完成。有其他方法来验证操作是否成功。

将此转换为完全异步代码的示例代码:

// This now has to be external to processing code, and possibly shared as well.
ExecutorService service = Executors.newFixedThreadPool(5);

// and the processing code goes like this:
List<CompletableFuture<Boolean>> futures = new ArrayList<>();
for (EmployeeSave save : empList) {
  futures.add(CompletableFuture.supplyAsync(save::call, service));
}

// If you do actually need a notification, then you need to store identify the running request somehow. For example, using Id or parameters
String processId = generateSaveProcessId();
runningSaveProcesses.store(
    processId,
    CompletableFuture.allOf(
        futures.toArray(new CompletableFuture[0]);
    )
);
// return the process identifier with "Ack" response
return <...Response( processId )...>