301608 Deregister shutdown hooks

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1949 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-06-09 07:22:08 +00:00
parent 21f0c161d2
commit 7f409167a7
2 changed files with 40 additions and 17 deletions

View File

@ -3,6 +3,7 @@ jetty-7.1.4-SNAPSHOT
+ 292814 Make QoSFilter and DoSFilter JMX manageable
+ 293222 Improve request log to handle/show asynchronous latency
+ 294212 Can not customize session cookie path
+ 301608 Deregister shutdown hooks
+ 302350 org.eclipse.jetty.server.NCSARequestLog is missing JavaDoc
+ 303661 Startup with jetty.sh-Script failes if JETTY_HOME is not writeable
for JETTY_USER

View File

@ -35,6 +35,7 @@ public class ShutdownThread extends Thread
{
private static final ShutdownThread _thread = new ShutdownThread();
private boolean _hooked;
private final List<LifeCycle> _lifeCycles = new CopyOnWriteArrayList<LifeCycle>();
/* ------------------------------------------------------------ */
@ -44,10 +45,32 @@ public class ShutdownThread extends Thread
* Registers the instance as shutdown hook with the Java Runtime
*/
private ShutdownThread()
{
}
/* ------------------------------------------------------------ */
private synchronized void hook()
{
try
{
if (!_hooked)
Runtime.getRuntime().addShutdownHook(this);
_hooked=true;
}
catch(Exception e)
{
Log.ignore(e);
Log.info("shutdown already commenced");
}
}
/* ------------------------------------------------------------ */
private synchronized void unhook()
{
try
{
_hooked=false;
Runtime.getRuntime().removeShutdownHook(this);
}
catch(Exception e)
{
@ -71,18 +94,24 @@ public class ShutdownThread extends Thread
public static synchronized void register(LifeCycle... lifeCycles)
{
_thread._lifeCycles.addAll(Arrays.asList(lifeCycles));
if (_thread._lifeCycles.size()>0)
_thread.hook();
}
/* ------------------------------------------------------------ */
public static synchronized void register(int index, LifeCycle... lifeCycles)
{
_thread._lifeCycles.addAll(index,Arrays.asList(lifeCycles));
if (_thread._lifeCycles.size()>0)
_thread.hook();
}
/* ------------------------------------------------------------ */
public static synchronized void deregister(LifeCycle lifeCycle)
{
_thread._lifeCycles.remove(lifeCycle);
if (_thread._lifeCycles.size()==0)
_thread.unhook();
}
/* ------------------------------------------------------------ */
@ -101,11 +130,4 @@ public class ShutdownThread extends Thread
}
}
}
/* ------------------------------------------------------------ */
protected Object readResolve()
throws ObjectStreamException
{
return _thread;
}
}