summaryrefslogtreecommitdiff
path: root/java/src/Ice/Application.java
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2003-06-20 20:18:16 +0000
committerMarc Laukien <marc@zeroc.com>2003-06-20 20:18:16 +0000
commita7ced2038deb8ba2e0fe0e85517906b9ebe75d03 (patch)
treec4fb2bcc5483fa18f61b6dc8c7ac22403e747ed0 /java/src/Ice/Application.java
parentFixed incorrect property setting for Glacier tracing. (diff)
downloadice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.tar.bz2
ice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.tar.xz
ice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.zip
added destroyOnInterrupt() to Application
Diffstat (limited to 'java/src/Ice/Application.java')
-rw-r--r--java/src/Ice/Application.java82
1 files changed, 80 insertions, 2 deletions
diff --git a/java/src/Ice/Application.java b/java/src/Ice/Application.java
index fbdf01498bc..a5cd647eb67 100644
--- a/java/src/Ice/Application.java
+++ b/java/src/Ice/Application.java
@@ -64,9 +64,9 @@ public abstract class Application
}
//
- // The default is to shutdown when a signal is received.
+ // The default is to destroy when a signal is received.
//
- shutdownOnInterrupt();
+ destroyOnInterrupt();
status = run(argHolder.value);
}
@@ -106,6 +106,11 @@ public abstract class Application
synchronized(this)
{
+ if(_destroyHook != null)
+ {
+ _destroyHook.done();
+ }
+
if(_shutdownHook != null)
{
_shutdownHook.done();
@@ -142,6 +147,31 @@ public abstract class Application
}
synchronized public static void
+ destroyOnInterrupt()
+ {
+ if(_destroyHook == null)
+ {
+ //
+ // As soon as the destroy hook ends all the threads are
+ // terminated. So the destroy hook will join the current
+ // thread before to end.
+ //
+ _destroyHook = new DestroyHook();
+ try
+ {
+ Runtime.getRuntime().addShutdownHook(_destroyHook);
+ }
+ catch(java.lang.IllegalStateException ex)
+ {
+ if(_communicator != null)
+ {
+ _communicator.destroy();
+ }
+ }
+ }
+ }
+
+ synchronized public static void
shutdownOnInterrupt()
{
if(_shutdownHook == null)
@@ -197,6 +227,53 @@ public abstract class Application
_interrupted = true;
}
+ static class DestroyHook extends Thread
+ {
+ DestroyHook()
+ {
+ _done = false;
+ }
+
+ public void
+ run()
+ {
+ synchronized(_doneMutex)
+ {
+ setInterrupt();
+
+ Communicator communicator = communicator();
+ if(communicator != null)
+ {
+ communicator.destroy();
+ }
+
+ while(!_done)
+ {
+ try
+ {
+ _doneMutex.wait();
+ }
+ catch(InterruptedException ex)
+ {
+ }
+ }
+ }
+ }
+
+ void
+ done()
+ {
+ synchronized(_doneMutex)
+ {
+ _done = true;
+ _doneMutex.notify();
+ }
+ }
+
+ private boolean _done;
+ private java.lang.Object _doneMutex = new java.lang.Object();
+ }
+
static class ShutdownHook extends Thread
{
ShutdownHook()
@@ -246,6 +323,7 @@ public abstract class Application
private static String _appName;
private static Communicator _communicator;
+ private static DestroyHook _destroyHook;
private static ShutdownHook _shutdownHook;
private static boolean _interrupted;
}