private static final synchronized void initSingletonInstance() { if (null == singletonInstance) { // singletonInstance = SingletonInstance.createFileLock(SINGLE_INSTANCE_LOCK_POLL, // SINGLE_INSTANCE_LOCK_FILE); singletonInstance = SingletonInstance.createServerSocket( SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); if (!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) { throw new RuntimeException( "Fatal: Could not lock single instance: " + singletonInstance.getName()); } } }
@AfterClass public static void oneTimeTearDown() { // one-time cleanup code System.gc(); // force cleanup singletonInstance.unlock(); }