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:
parent
21f0c161d2
commit
7f409167a7
|
@ -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
|
||||
|
|
|
@ -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>();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -45,17 +46,39 @@ public class ShutdownThread extends Thread
|
|||
*/
|
||||
private ShutdownThread()
|
||||
{
|
||||
try
|
||||
{
|
||||
Runtime.getRuntime().addShutdownHook(this);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.ignore(e);
|
||||
Log.info("shutdown already commenced");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
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)
|
||||
{
|
||||
Log.ignore(e);
|
||||
Log.info("shutdown already commenced");
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Returns the instance of the singleton
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue