1 3 20 21 package edu.neu.ccs.jmk.sun; 22 23 import sun.tools.javac.*; 24 import edu.neu.ccs.jmk.Operator; 25 import edu.neu.ccs.jmk.CommandFailedException; 26 import java.io.*; 27 28 39 public final class Javac 40 implements Operator, Runnable 41 { 42 private static final long CLEANER_DELAY=1000*30; 45 private static Thread cleaner_=null; 46 private static Main ji_=null; 47 private static long launchdate_=0; 48 49 public String getName() 50 { 51 return("Javac"); 52 } 53 54 public void run() 55 { 56 while ( System.currentTimeMillis()-launchdate_<CLEANER_DELAY ) 57 { 58 try 59 { 60 Thread.sleep(CLEANER_DELAY+1000); 61 } 62 catch ( Exception e ) 63 { 64 System.err.println(e.toString()); 65 } 66 } 67 68 synchronized(this) 70 { 71 ji_=null; 72 cleaner_=null; 73 System.gc(); 74 } 75 } 76 77 public void exec(String [] _args, PrintWriter _out) 78 throws CommandFailedException 79 { 80 if ( _args.length == 0 ) 81 throw new CommandFailedException("No args to " + getName()); 82 try 83 { 84 synchronized(this) 87 { 88 if ( ji_==null ) 89 { 90 ji_ = new Main(new OutputStreamToPrintWriter(_out), "javac"); 91 } 92 93 launchdate_=System.currentTimeMillis(); 94 if ( cleaner_==null ) 95 { 96 cleaner_=new Thread (this); 97 cleaner_.start(); 98 } 99 100 if ( ji_.compile(_args) == false ) 101 throw new CommandFailedException(getName() + " failed"); 102 } 103 } 104 catch ( CommandFailedException ex1 ) 105 { 106 throw ex1; 107 } 108 catch ( Exception ex2 ) 109 { 110 throw new CommandFailedException(getName() + " threw an exception -> "+ex2.toString()); 111 } 112 } 113 } 114 | Popular Tags |