From f25cc68fb1ed285563dae769d3cf1720eb0b3ecb Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 14 Dec 2005 13:45:12 +0000 Subject: [PATCH] removed possible threading error git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@356776 13f79535-47bb-0310-9956-ffa450edef68 --- .../activeio/journal/active/ControlFile.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/activeio/src/java/org/activeio/journal/active/ControlFile.java b/activeio/src/java/org/activeio/journal/active/ControlFile.java index 34c6278d31..73b89a09a2 100644 --- a/activeio/src/java/org/activeio/journal/active/ControlFile.java +++ b/activeio/src/java/org/activeio/journal/active/ControlFile.java @@ -66,15 +66,15 @@ final public class ControlFile implements Disposable { * @throws IOException */ public void lock() throws IOException { - if( lock==null ) { - Set set = getVmLockSet(); - synchronized(set) { - if( !set.add(canonicalPath) ) { + Set set = getVmLockSet(); + synchronized (set) { + if (lock == null) { + if (!set.add(canonicalPath)) { throw new IOException("Journal is already opened by this application."); } - + lock = channel.tryLock(); - if( lock ==null ) { + if (lock == null) { set.remove(canonicalPath); throw new IOException("Journal is already opened by another application"); } @@ -84,15 +84,16 @@ final public class ControlFile implements Disposable { /** * Un locks the control file. - * @throws IOException + * + * @throws IOException */ public void unlock() throws IOException { - if( lock != null ) { - Set set = getVmLockSet(); - synchronized(set) { - lock.release(); - lock=null; + Set set = getVmLockSet(); + synchronized (set) { + if (lock != null) { set.remove(canonicalPath); + lock.release(); + lock = null; } } }