activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
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 GMT
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 <gary.tully@gmail.com>
Authored: Wed Oct 14 15:08:03 2015 +0100
Committer: gtully <gary.tully@gmail.com>
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();
 


Mime
View raw message