From: jprocter Date: Fri, 24 Mar 2006 19:13:22 +0000 (+0000) Subject: fixed leaky lock (answers todo about verifying that channel.close() should be called... X-Git-Tag: Release_0.2~309 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=caac4dd640d337f251e934ad1fa5c81e2b040028;p=vamsas.git fixed leaky lock (answers todo about verifying that channel.close() should be called before lock.release()) git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@211 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/Lock.java b/src/org/vamsas/client/simpleclient/Lock.java index 5c052f6..903214d 100644 --- a/src/org/vamsas/client/simpleclient/Lock.java +++ b/src/org/vamsas/client/simpleclient/Lock.java @@ -64,21 +64,24 @@ public class Lock { return false; } public void release() { + release(true); + } + public void release(boolean closeChannel) { try { - // TODO: verify that channel.close should be called after release() for rigourous locking. + // channel.close should be called before release() for rigourous locking. if (rafile!=null && rafile.getChannel()!=null) { if (rafile.getChannel().isOpen()) { + if (closeChannel && rafile.getChannel().isOpen()) + rafile.getChannel().close(); if (lock!=null && lock.isValid()) lock.release(); - if (rafile.getChannel().isOpen()) - rafile.getChannel().close(); } } } catch (IOException e) { log.warn("Whilst releasing lock",e); } lock=null; - rafile=null; + rafile=null; } /** @@ -136,7 +139,8 @@ public class Lock { * @see java.lang.Object#finalize() */ protected void finalize() throws Throwable { - release(); + release(true); // we explicitly lose the lock here. + // log.debug("lock closing through garbage collection ?"); super.finalize(); }