Proxool connection pool warning analysis: appears to have started a thread named [HouseKeeper] but has failed to stop it, housekeeper
1. problem: the following warning appears in the log:
Warning The web application [ROOT] appears to have started a thread named [HouseKeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
Java. lang. Thread. sleep (Native Method)
Org. logicalcobwebs. proxool. HouseKeeperThread. run (HouseKeeperThread. java: 46)
2. Cause investigation:
The proxool connection pool is used. Check the source code and analyze it as follows:
Under certain circumstances of the Project, ProxoolFacade. shutdown (); is called and it will call:
protected static void shutdown(String finalizer, int delay) { ConnectionPool[] cps = ConnectionPoolManager.getInstance().getConnectionPools(); for (int i = 0; i < cps.length; i++) { removeConnectionPool(finalizer, cps[i], delay); } // If a shutdown hook was registered then remove it try { if (shutdownHook != null) { ShutdownHook.remove(shutdownHook); } } catch (Throwable t) { if (LOG.isDebugEnabled()) { LOG.debug("Unanticipated error during removal of ShutdownHook. Ignoring it.", t); } } // Stop threads PrototyperController.shutdown(); HouseKeeperController.shutdown(); }
Close the connection pool first, and then close a housekeeper demaon thread at the end:
HouseKeeperController.shutdown();
/** * Stop all house keeper threads. */ protected static void shutdown() { synchronized(LOCK) { Iterator i = houseKeeperThreads.iterator(); while (i.hasNext()) { HouseKeeperThread hkt = (HouseKeeperThread) i.next(); LOG.info("Stopping " + hkt.getName() + " thread"); hkt.cancel(); } houseKeeperThreads.clear(); } }
The cancel () method is called for each housekeeper thread. Generally, there is only one housekeeper thread:
hkt.cancel();
public class HouseKeeperThread extends Thread { private static final Log LOG = LogFactory.getLog(HouseKeeperThread.class); private boolean stop; public HouseKeeperThread(String name) { setDaemon(true); setName(name); } public void run() { while (!stop) { HouseKeeper hk = HouseKeeperController.getHouseKeeperToRun(); while (hk != null && !stop) { try {// if (LOG.isDebugEnabled()) {// LOG.debug("About to sweep " + hk.getAlias());// } hk.sweep(); } catch (ProxoolException e) { LOG.error("Couldn't sweep " + hk.getAlias(), e); } hk = HouseKeeperController.getHouseKeeperToRun(); } try { Thread.sleep(5000); } catch (InterruptedException e) { LOG.error("Interrupted", e); } } } protected void cancel() { stop = true; }}
Nima stop is a normal boolean variable, and it should be modified using volatile!
The cause of the error is that the housekeeper thread runs every five seconds, and when the system wants to stop it, it is sleep, so an exception is thrown:
Warning The web application [ROOT] appears to have started a thread named [HouseKeeper] but has failed to stop it. this is very likely to create a memory leak. stack trace of thread: java. lang. thread. sleep (Native Method) org. logicalcobwebs. proxool. houseKeeperThread. run (HouseKeeperThread. java: 46)
However, because stop = true is set, when sleep is completed, it may also judge stop = true or stop = false, because volatile is not used here!
The worst result is that a deamon jvm thread named "HouseKeeper" is not successfully closed.
3. The log shows that the database connection pool has been properly closed:
ContainerBackgroundProcessor[StandardEngine[Catalina]] - Proxool shoutdown [INFO ] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:484):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Shutting down 'autumn' pool immediately [ContainerBackgroundProcessor[StandardEngine[Catalina]]] [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/05/00) - #0006 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #6 closed [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/04/00) - #0005 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #5 closed [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/03/00) - #0004 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #4 closed [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/02/00) - #0003 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #3 closed [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/01/00) - #0002 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #2 closed [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/00/00) - #0001 removed because of shutdown. [DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #1 closed [INFO ] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:564):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 'autumn' pool has been closed down by ContainerBackgroundProcessor[StandardEngine[Catalina]] in 6 milliseconds. [DEBUG] org.logicalcobwebs.proxool.ShutdownHook.remove(ShutdownHook.java:41):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Removed shutdownHook [INFO ] org.logicalcobwebs.proxool.PrototyperController.shutdown(PrototyperController.java:100):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Stopping Prototyper thread [INFO ] org.logicalcobwebs.proxool.HouseKeeperController.shutdown(HouseKeeperController.java:107):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Stopping HouseKeeper thread
The problem of database connection leakage caused by poxool is ruled out.