summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/locks
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-09-21 13:59:38 +0200
committerSven Gothel <[email protected]>2012-09-21 13:59:38 +0200
commitc8a9b89b1f316c259eaec68309f32fdd8289e375 (patch)
tree14020ec7d53b2d70ba1ceb21ce399549b943f8a7 /src/java/com/jogamp/common/util/locks
parent4aa7541635e1fd8ae6a41f1d32d85828a18f7028 (diff)
SingletonInstanceServerSocket: Add unit tests; Create new server Thread @ start, otherwise we may collide w/ a failed start. Misc: Cleanup / reuse strings.
Diffstat (limited to 'src/java/com/jogamp/common/util/locks')
-rw-r--r--src/java/com/jogamp/common/util/locks/SingletonInstance.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/java/com/jogamp/common/util/locks/SingletonInstance.java b/src/java/com/jogamp/common/util/locks/SingletonInstance.java
index 5f2718b..476c269 100644
--- a/src/java/com/jogamp/common/util/locks/SingletonInstance.java
+++ b/src/java/com/jogamp/common/util/locks/SingletonInstance.java
@@ -95,19 +95,19 @@ public abstract class SingletonInstance implements Lock {
locked = tryLockImpl();
if(locked) {
if(DEBUG) {
- System.err.println("SLOCK "+System.currentTimeMillis()+" +++ "+getName()+" - Locked ");
+ System.err.println(infoPrefix()+" +++ "+getName()+" - Locked ");
}
return true;
}
if(DEBUG && 0==i) {
- System.err.println("SLOCK "+System.currentTimeMillis()+" ??? "+getName()+" - Wait for lock");
+ System.err.println(infoPrefix()+" III "+getName()+" - Wait for lock");
}
Thread.sleep(poll_ms);
maxwait -= poll_ms;
i++;
} while ( 0 < maxwait ) ;
} catch ( InterruptedException ie ) {
- throw new RuntimeException("SLOCK "+System.currentTimeMillis()+" EEE "+getName()+" - couldn't get lock", ie);
+ throw new RuntimeException(infoPrefix()+" EEE "+getName()+" - couldn't get lock", ie);
}
return false;
}
@@ -118,8 +118,7 @@ public abstract class SingletonInstance implements Lock {
if(locked) {
locked = !unlockImpl();
if(DEBUG) {
- System.err.println("SLOCK "+System.currentTimeMillis()+" --- "+getName()+" - Unlock "
- + ( locked ? "failed" : "ok" ) );
+ System.err.println(infoPrefix()+" --- "+getName()+" - Unlock "+ ( locked ? "failed" : "ok" ) );
}
}
}
@@ -130,6 +129,10 @@ public abstract class SingletonInstance implements Lock {
return locked;
}
+ protected String infoPrefix() {
+ return "SLOCK [T "+Thread.currentThread().getName()+" @ "+System.currentTimeMillis()+" ms";
+ }
+
private final long poll_ms;
private boolean locked = false;
}