From c8a9b89b1f316c259eaec68309f32fdd8289e375 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 21 Sep 2012 13:59:38 +0200 Subject: SingletonInstanceServerSocket: Add unit tests; Create new server Thread @ start, otherwise we may collide w/ a failed start. Misc: Cleanup / reuse strings. --- .../com/jogamp/common/util/locks/SingletonInstance.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/java/com/jogamp/common/util/locks') 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; } -- cgit v1.2.3