/Users/lyon/j4p/src/gui/run/RunJobUtils.java

1    package gui.run; 
2     
3    import utils.SystemUtils; 
4     
5    import java.io.File; 
6     
7    /** 
8     * Copyright DocJava, inc. User: lyon 
9     * <p/> 
10    * Date: Nov 15, 2004 
11    * <p/> 
12    * Time: 5:59:55 AM 
13    */ 
14   public class RunJobUtils { 
15       public static void main(String[] args) { 
16           testRunJobFile(); 
17       } 
18    
19       private static void testRunJobFile() { 
20           final File f = new File(SystemUtils.getUserDir() 
21                   +SystemUtils.getDirectorySeparator() 
22           +".killScreenSaver"); 
23           killJvmIfFileExists(f); 
24       } 
25       /** 
26        * Kill the JVM if the file exists. Great for 
27        * an asynchronous kill of the present JVM by 
28        * another JVM. Better make sure you clean up your 
29        * mess on exit, since this is SUDDEN DEATH. 
30        * This program has the side-effect of deleting 
31        * the lock file, on exit. 
32        * @param f the lock file to signal the kill. 
33        */ 
34       public static void killJvmIfFileExists(final File f) { 
35           new RunJob(1){ 
36               public void run(){ 
37                   if (f.exists()){ 
38                       f.delete(); 
39                       System.exit(0); 
40                   } 
41    
42               } 
43           }; 
44       } 
45   } 
46