Only unlock a service lock if we managed to lock it

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@637454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-03-15 18:59:49 +00:00
parent 8d28bbfdab
commit 1987cfa234
1 changed files with 5 additions and 2 deletions

View File

@ -889,10 +889,11 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
new Thread("ActiveMQ Transport Stopper: "+ transport.getRemoteAddress()) { new Thread("ActiveMQ Transport Stopper: "+ transport.getRemoteAddress()) {
@Override @Override
public void run() { public void run() {
boolean locked = false;
// make sure we are not servicing client requests while we are shutting down. // make sure we are not servicing client requests while we are shutting down.
try { try {
//we could be waiting a long time if the network has gone - so only wait 1 second //we could be waiting a long time if the network has gone - so only wait 1 second
serviceLock.writeLock().tryLock(1,TimeUnit.SECONDS); locked = serviceLock.writeLock().tryLock(1,TimeUnit.SECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.debug("Try get writeLock interrupted ",e); LOG.debug("Try get writeLock interrupted ",e);
} }
@ -903,7 +904,9 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
LOG.debug("Error occured while shutting down a connection to '" + transport.getRemoteAddress()+ "': ", e); LOG.debug("Error occured while shutting down a connection to '" + transport.getRemoteAddress()+ "': ", e);
} finally { } finally {
stopped.countDown(); stopped.countDown();
serviceLock.writeLock().unlock(); if (locked) {
serviceLock.writeLock().unlock();
}
} }
} }
}.start(); }.start();