我遇到需要啓動運行4小時的任務的情況。我正在使用servlet來啓動流程。但是我收到一個內存泄漏異常。如何使用servlet運行長時間運行的進程
Aug 10, 2016 2:08:05 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/] has started
Aug 10, 2016 2:08:05 PM org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated for Servlet [Servlet]
Aug 10, 2016 2:08:06 PM org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated for Servlet [Servlet]
Aug 10, 2016 2:08:07 PM org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated for Servlet [DayZeroServlet]
Aug 10, 2016 2:08:07 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [xxx#Day0MS] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation. Stack trace of request processing thread:
java.net.SocketOutputStream.socketWrite0(Native Method)
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
下面是代碼,我使用
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
if (!GehDAO.getProcessFlag()) {
GehDAO.updateProcessFlag(true);
out.println("Transformation started ...");
closeWriter(out);
execute(); // This step start the long running process
}
else {
out.println("Transformation Already Running ...");
closeWriter(out);
}
}
有沒有一種方法,我可以運行在單獨的進程中execute()方法?
我想在一個月內運行一次或兩次這個servlet,以啓動長時間運行的進程。
請注意,您的代碼不是線程安全的。 – xehpuk