Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC69B183EA for ; Wed, 14 Oct 2015 14:19:46 +0000 (UTC) Received: (qmail 46639 invoked by uid 500); 14 Oct 2015 14:19:43 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 46602 invoked by uid 500); 14 Oct 2015 14:19:43 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 46593 invoked by uid 99); 14 Oct 2015 14:19:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Oct 2015 14:19:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2F385DFFA2; Wed, 14 Oct 2015 14:19:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gtully@apache.org To: commits@activemq.apache.org Message-Id: <306fef57cfea483fbd7736ba47e4c671@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: https://issues.apache.org/jira/browse/AMQ-4705 - ensure jvm lock system property is cleared in the event of lock release throwing exception. Date: Wed, 14 Oct 2015 14:19:43 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/master af09b4586 -> b285d1018 https://issues.apache.org/jira/browse/AMQ-4705 - ensure jvm lock system property is cleared in the event of lock release throwing exception. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b285d101 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b285d101 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b285d101 Branch: refs/heads/master Commit: b285d1018803ceb4fdf7ea14c178de1e0abc9c8a Parents: af09b45 Author: gtully Authored: Wed Oct 14 15:08:03 2015 +0100 Committer: gtully Committed: Wed Oct 14 15:08:59 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/activemq/util/LockFile.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/b285d101/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java b/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java index 516c5c2..b454c41 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java +++ b/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java @@ -42,6 +42,7 @@ public class LockFile { private int lockCounter; private final boolean deleteOnUnlock; private volatile boolean locked; + private String lockSystemPropertyName = ""; private static final Logger LOG = LoggerFactory.getLogger(LockFile.class); @@ -64,10 +65,11 @@ public class LockFile { IOHelper.mkdirs(file.getParentFile()); synchronized (LockFile.class) { - if (System.getProperty(getVmLockKey()) != null) { - throw new IOException("File '" + file + "' could not be locked as lock is already held for this jvm."); + lockSystemPropertyName = getVmLockKey(); + if (System.getProperty(lockSystemPropertyName) != null) { + throw new IOException("File '" + file + "' could not be locked as lock is already held for this jvm. Value: " + System.getProperty(lockSystemPropertyName)); } - System.setProperty(getVmLockKey(), new Date().toString()); + System.setProperty(lockSystemPropertyName, new Date().toString()); } try { if (lock == null) { @@ -86,7 +88,7 @@ public class LockFile { randomAccessLockFile.getChannel().force(true); lastModified = file.lastModified(); lockCounter++; - System.setProperty(getVmLockKey(), new Date().toString()); + System.setProperty(lockSystemPropertyName, new Date().toString()); locked = true; } else { // new read file for next attempt @@ -101,7 +103,7 @@ public class LockFile { } finally { synchronized (LockFile.class) { if (lock == null) { - System.getProperties().remove(getVmLockKey()); + System.getProperties().remove(lockSystemPropertyName); } } } @@ -123,10 +125,13 @@ public class LockFile { if (lock != null) { try { lock.release(); - System.getProperties().remove(getVmLockKey()); } catch (Throwable ignore) { + } finally { + if (lockSystemPropertyName != null) { + System.getProperties().remove(lockSystemPropertyName); + } + lock = null; } - lock = null; } closeReadFile();