aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/scripts/runtest.sh4
-rw-r--r--src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java3
-rw-r--r--src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java47
3 files changed, 45 insertions, 9 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh
index c852493..7979a13 100755
--- a/make/scripts/runtest.sh
+++ b/make/scripts/runtest.sh
@@ -75,6 +75,8 @@ function onetest() {
#onetest com.jogamp.common.util.TestIteratorIndexCORE 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.locks.TestRecursiveLock01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.locks.TestRecursiveThreadGroupLock01 2>&1 | tee -a $LOG
+onetest com.jogamp.common.util.locks.TestSingletonServerSocket00 2>&1 | tee -a $LOG
+onetest com.jogamp.common.util.locks.TestSingletonServerSocket01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestArrayHashSet01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.IntIntHashMapTest 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.IntObjectHashMapTest 2>&1 | tee -a $LOG
@@ -88,7 +90,7 @@ function onetest() {
#onetest com.jogamp.common.util.TestPlatform01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestRunnableTask01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestIOUtil01 2>&1 | tee -a $LOG
-onetest com.jogamp.common.util.TestTempJarCache 2>&1 | tee -a $LOG
+#onetest com.jogamp.common.util.TestTempJarCache 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestJarUtil 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.AssetURLConnectionUnregisteredTest 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.AssetURLConnectionRegisteredTest 2>&1 | tee -a $LOG
diff --git a/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java b/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java
index f369941..c8a05ed 100644
--- a/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java
+++ b/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java
@@ -79,6 +79,9 @@ public class SingletonInstanceFileLock extends SingletonInstance {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
+ if(isLocked()) {
+ System.err.println("SLOCK "+System.currentTimeMillis()+" XXX "+getName()+" - Unlock @ JVM Shutdown");
+ }
unlock();
}
});
diff --git a/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java b/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java
index 14a6aaf..eab687d 100644
--- a/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java
+++ b/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java
@@ -70,7 +70,13 @@ public class SingletonInstanceServerSocket extends SingletonInstance {
}
fullName = ilh.toString()+":"+portNumber;
- singletonServer = new Server(ilh, portNumber);
+ singletonServer = new Server(ilh, portNumber);
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ singletonServer.kill();
+ }
+ });
}
public final InetAddress getLocalInetAddress() {
@@ -120,23 +126,23 @@ public class SingletonInstanceServerSocket extends SingletonInstance {
private Object syncOnStartStop = new Object();
private ServerSocket serverSocket = null;
+ private Thread serverThread = null;
public Server(InetAddress localInetAddress, int portNumber) {
this.localInetAddress = localInetAddress;
this.portNumber = portNumber;
+ this.serverThread = new Thread(this);
+ this.serverThread.setDaemon(true); // be a daemon, don't keep the JVM running
}
public final InetAddress getLocalInetAddress() { return localInetAddress; }
public final int getPortNumber() { return portNumber; }
- public boolean start() {
+ public final boolean start() {
if(alive) return true;
-
- Thread t = new Thread(this);
- t.setDaemon(true); // be a daemon, don't keep the JVM running
-
+
synchronized (syncOnStartStop) {
- t.start();
+ serverThread.start();
try {
syncOnStartStop.wait();
} catch (InterruptedException ie) {
@@ -164,8 +170,33 @@ public class SingletonInstanceServerSocket extends SingletonInstance {
}
if(alive) {
System.err.println("SLOCK "+System.currentTimeMillis()+" EEE "+getName()+" - Unable to remove lock: ServerThread still alive ?");
+ kill();
+ alive = false;
}
- return !alive;
+ serverThread = new Thread(this);
+ serverThread.setDaemon(true); // be a daemon, don't keep the JVM running
+ return true;
+ }
+
+ /**
+ * Brutally kill server thread and close socket regardless.
+ * This is out last chance for JVM shutdown.
+ */
+ @SuppressWarnings("deprecation")
+ public final void kill() {
+ if(alive) {
+ System.err.println("SLOCK "+System.currentTimeMillis()+" XXX "+getName()+" - Kill @ JVM Shutdown");
+ }
+ try {
+ serverThread.stop();
+ } catch(Throwable t) { }
+ if(null != serverSocket) {
+ try {
+ final ServerSocket ss = serverSocket;
+ serverSocket = null;
+ ss.close();
+ } catch (Throwable t) { }
+ }
}
public final boolean isRunning() { return alive; }