Properly shut down worker threads to avoid leak
git-svn-id: https://brutex.net/svn/xservices/trunk@184 e7e49efb-446e-492e-b9ec-fcafc1997a86master
parent
98f2419840
commit
bba63ca750
|
@ -23,6 +23,7 @@ import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -55,11 +56,12 @@ public class FindingsCacheServlet extends HttpServlet {
|
||||||
.getLogger(FindingsCacheServlet.class);
|
.getLogger(FindingsCacheServlet.class);
|
||||||
private final List<File> configfiles = new ArrayList<File>();
|
private final List<File> configfiles = new ArrayList<File>();
|
||||||
private final ObjectFactory FACTORY = new ObjectFactory();
|
private final ObjectFactory FACTORY = new ObjectFactory();
|
||||||
|
private ExecutorService executor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
ExecutorService executor = (ExecutorService) getServletContext()
|
executor = (ExecutorService) getServletContext()
|
||||||
.getAttribute("CACHE_EXECUTOR");
|
.getAttribute("CACHE_EXECUTOR");
|
||||||
|
|
||||||
if(! this.initConfigList()) return;
|
if(! this.initConfigList()) return;
|
||||||
|
@ -116,6 +118,7 @@ public class FindingsCacheServlet extends HttpServlet {
|
||||||
|
|
||||||
|
|
||||||
executor.submit(new ThisRunnable(cbean));
|
executor.submit(new ThisRunnable(cbean));
|
||||||
|
|
||||||
}
|
}
|
||||||
logger.info("FindingsCacheServlet has been initialized.");
|
logger.info("FindingsCacheServlet has been initialized.");
|
||||||
|
|
||||||
|
@ -343,4 +346,24 @@ public class FindingsCacheServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see javax.servlet.GenericServlet#destroy()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
executor.shutdown();
|
||||||
|
try {
|
||||||
|
executor.awaitTermination(3, TimeUnit.SECONDS);
|
||||||
|
logger.info("Cache Worker Threads have shut down.");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.error("Cache Worker Threads did not terminate within timeout.", e);
|
||||||
|
}
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue