mirror of https://github.com/apache/activemq.git
Applied patch for https://issues.apache.org/jira/browse/AMQ-3301
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1326252 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f0ef2e670
commit
50d3e8e09a
|
@ -51,36 +51,47 @@ public class LockFile {
|
|||
return;
|
||||
}
|
||||
|
||||
if( lockCounter>0 ) {
|
||||
if (lockCounter > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IOHelper.mkdirs(file.getParentFile());
|
||||
if (System.getProperty(getVmLockKey()) != null) {
|
||||
throw new IOException("File '" + file + "' could not be locked as lock is already held for this jvm.");
|
||||
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.");
|
||||
}
|
||||
System.setProperty(getVmLockKey(), new Date().toString());
|
||||
}
|
||||
if (lock == null) {
|
||||
readFile = new RandomAccessFile(file, "rw");
|
||||
IOException reason = null;
|
||||
try {
|
||||
lock = readFile.getChannel().tryLock(0, Math.max(1, readFile.getChannel().size()), false);
|
||||
} catch (OverlappingFileLockException e) {
|
||||
reason = IOExceptionSupport.create("File '" + file + "' could not be locked.",e);
|
||||
} catch (IOException ioe) {
|
||||
reason = ioe;
|
||||
}
|
||||
if (lock != null) {
|
||||
lockCounter++;
|
||||
System.setProperty(getVmLockKey(), new Date().toString());
|
||||
} else {
|
||||
// new read file for next attempt
|
||||
closeReadFile();
|
||||
if (reason != null) {
|
||||
throw reason;
|
||||
try {
|
||||
if (lock == null) {
|
||||
readFile = new RandomAccessFile(file, "rw");
|
||||
IOException reason = null;
|
||||
try {
|
||||
lock = readFile.getChannel().tryLock(0, Math.max(1, readFile.getChannel().size()), false);
|
||||
} catch (OverlappingFileLockException e) {
|
||||
reason = IOExceptionSupport.create("File '" + file + "' could not be locked.", e);
|
||||
} catch (IOException ioe) {
|
||||
reason = ioe;
|
||||
}
|
||||
if (lock != null) {
|
||||
lockCounter++;
|
||||
System.setProperty(getVmLockKey(), new Date().toString());
|
||||
} else {
|
||||
// new read file for next attempt
|
||||
closeReadFile();
|
||||
if (reason != null) {
|
||||
throw reason;
|
||||
}
|
||||
throw new IOException("File '" + file + "' could not be locked.");
|
||||
}
|
||||
throw new IOException("File '" + file + "' could not be locked.");
|
||||
}
|
||||
|
||||
}
|
||||
} finally {
|
||||
synchronized (LockFile.class) {
|
||||
if (lock == null) {
|
||||
System.getProperties().remove(getVmLockKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +103,7 @@ public class LockFile {
|
|||
}
|
||||
|
||||
lockCounter--;
|
||||
if( lockCounter!=0 ) {
|
||||
if (lockCounter != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -107,7 +118,7 @@ public class LockFile {
|
|||
}
|
||||
closeReadFile();
|
||||
|
||||
if( deleteOnUnlock ) {
|
||||
if (deleteOnUnlock) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue