From 9d9b664b45909d1f3a718b0edb9119d0afa88baa Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 8 Mar 2007 14:18:23 +0000 Subject: [PATCH] simplified and bugfixed occasional lock contention. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@355 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/client/simpleclient/FileLock.java | 5 +++-- src/uk/ac/vamsas/client/simpleclient/NativeLock.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/FileLock.java b/src/uk/ac/vamsas/client/simpleclient/FileLock.java index c7d6150..c069d95 100644 --- a/src/uk/ac/vamsas/client/simpleclient/FileLock.java +++ b/src/uk/ac/vamsas/client/simpleclient/FileLock.java @@ -48,9 +48,10 @@ public class FileLock extends Lock { */ private void tidy() { if (_lock!=null) { - if ( advisory!=null) + if ( advisory!=null) { advisory.release(true); - advisory.target.deleteOnExit(); + advisory.target.deleteOnExit(); + } advisory=null; _lock=null; } diff --git a/src/uk/ac/vamsas/client/simpleclient/NativeLock.java b/src/uk/ac/vamsas/client/simpleclient/NativeLock.java index 8a0124c..69b7155 100644 --- a/src/uk/ac/vamsas/client/simpleclient/NativeLock.java +++ b/src/uk/ac/vamsas/client/simpleclient/NativeLock.java @@ -70,9 +70,11 @@ public class NativeLock extends Lock { } public void release(boolean closeChannel) { + if (lock==null) + return; try { // channel.close should be called before release() for rigourous locking. - if (rafile!=null && rafile.getFD().valid() && rafile.getChannel()!=null && lock.isValid()) { + if (lock.isValid() && rafile!=null && rafile.getFD().valid() && rafile.getChannel()!=null) { if (closeChannel && rafile.getChannel().isOpen()) { rafile.close(); rafile=null; -- 1.7.10.2