added better check for file change (length + last modified)
[vamsas.git] / src / org / vamsas / client / simpleclient / Lock.java
index d7239e6..a185233 100644 (file)
@@ -31,7 +31,7 @@ public class Lock {
         if (!lockfile.createNewFile()) {
           return;
         }
-
+      
       lock = (rafile=new RandomAccessFile(lockfile,"rw")).getChannel().tryLock();
     } catch (FileNotFoundException e) {
       System.err.println("Error! Couldn't create a lockfile at "
@@ -50,13 +50,22 @@ public class Lock {
     }
     return false;
   }
-
+  public void release() {
+    if (lock!=null) {
+      try {
+        rafile.close();
+        lock.release();
+      } catch (IOException e) {
+        // TODO Auto-generated catch block
+        e.printStackTrace(System.err);
+      }
+    }
+  }
   /* Explicitly release lock (probably don't need to do this!)
    * @see java.lang.Object#finalize()
    */
   protected void finalize() throws Throwable {
-    if (lock!=null)
-      lock.release();
+    release();
     super.finalize();
   }