java防止一个程序运行多次!

     public void run() {
      closeLock();
      deleteFile();
     }
    });
    return false;
   } catch (Exception e) {
    closeLock();
    return true;
   }
}

protected void deleteFile() {
   try {
    file.delete();
   } catch (Exception e) {

   }

}

private void closeLock() {
   try {
    lock.release();
   } catch (Exception e) {

   }

   try {
    channel.close();
   } catch (Exception e) {

   }

}

public static void main(String[] args) {
   A1 a = new A1(".lock");
   if (a.isAppActive() == true)
    JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");

   try {
    Thread.sleep(10000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

}

}

http://hi.baidu.com/lirong1978/item/ff8671b940d7bff163388ea4

你可能感兴趣的:(java)