2013/10/17 <ma...@apache.org>: > Author: markt > Date: Thu Oct 17 10:32:21 2013 > New Revision: 1533035 > > URL: http://svn.apache.org/r1533035 > Log: > Avoid hangs on shutdown > > Modified: > > tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java >
I expect this to a) fail when running with a security manager b) cause a memory leak when examples app is reloaded, as you will get a new instance of ShutdownDetection class in webapp's classloader and new instance of shutdown hook. > Modified: > tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java > URL: > http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java?rev=1533035&r1=1533034&r2=1533035&view=diff > ============================================================================== > --- > tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java > (original) > +++ > tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java > Thu Oct 17 10:32:21 2013 > @@ -316,7 +316,9 @@ public final class Room { > public void run() { > closed = true; > drawmessageBroadcastTimer.cancel(); > - roomGraphics.dispose(); > + if (!ShutdownDetection.hasShutdownStarted()) { > + roomGraphics.dispose(); > + } > } > }); > } > @@ -412,4 +414,23 @@ public final class Room { > client.sendMessage(new StringWebsocketMessage(completeMsg)); > } > } > + > + > + static { > + Runtime.getRuntime().addShutdownHook(new ShutdownDetection()); > + } > + > + > + private static class ShutdownDetection extends Thread { > + private static volatile boolean shutdownStarted = false; > + > + private static boolean hasShutdownStarted() { > + return shutdownStarted; > + } > + > + @Override > + public void run() { > + shutdownStarted = true; > + } > + } > } > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org