From c724c5585a7d245621daee3022f0b10a14ccb3ba Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 24 Oct 2005 13:31:23 +0000 Subject: [PATCH] added automatic channel closure for failed locks. (suggest this class becomes a singleton?) git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@74 be28352e-c001-0410-b1a7-c7978e42abec --- src/org/vamsas/client/simpleclient/Lock.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/org/vamsas/client/simpleclient/Lock.java b/src/org/vamsas/client/simpleclient/Lock.java index ab159ba..300ea0e 100644 --- a/src/org/vamsas/client/simpleclient/Lock.java +++ b/src/org/vamsas/client/simpleclient/Lock.java @@ -33,6 +33,9 @@ public class Lock { } lock = (rafile=new RandomAccessFile(lockfile,"rw")).getChannel().tryLock(); + if (lock==null || !lock.isValid()) + // failed to get lock. Close the file channel + rafile.getChannel().close(); } catch (FileNotFoundException e) { System.err.println("Error! Couldn't create a lockfile at " + lockfile.getAbsolutePath()); -- 1.7.10.2