1 11 package org.eclipse.update.internal.configurator; 12 13 import java.io.*; 14 15 18 public class Locker_JavaIo implements Locker { 19 private File lockFile; 20 private RandomAccessFile lockRAF; 21 22 public Locker_JavaIo(File lockFile) { 23 this.lockFile = lockFile; 24 } 25 26 public synchronized boolean lock() throws IOException { 27 if (lockFile.exists()) 30 lockFile.delete(); 31 if (lockFile.exists()) 32 return false; 33 34 lockRAF = new RandomAccessFile(lockFile, "rw"); lockRAF.writeByte(0); 37 38 return true; 39 } 40 41 public synchronized void release() { 42 try { 43 if (lockRAF != null) { 44 lockRAF.close(); 45 lockRAF = null; 46 } 47 } catch (IOException e) { 48 } 50 if (lockFile != null) 51 lockFile.delete(); 52 } 53 } 54 | Popular Tags |