public static boolean lock() throws IOException {
  if (locked)   return true;
  if (lock.exists())   return false;
  lock.createNewFile();
  lock.deleteOnExit();
  locked=true;
  return true;
}

public static boolean lock ( ) throws IOException { if ( locked ) return true ; if ( lock . exists ( ) ) return false ; lock . createNewFile ( ) ; lock . deleteOnExit ( ) ; locked = true ; return true ; }
creates the lock file if it ' s not present and requests its deletion on program termination or informs that the program is already running if that ' s the case .
