1 package extensions; 2 3 56 57 import java.util.Date ; 58 import java.lang.reflect.Method ; 59 60 public class TWrap { 61 static long start = 0; 62 public static void mark(String msg) { 63 long elapsed = new Date ().getTime() - start; 64 System.out.println(msg + " (" + elapsed + "ms)"); 65 } 66 public static void main(String [] args) throws Exception { 67 Runtime.getRuntime().addShutdownHook(new MyShutdown()); 68 int numArgs = args.length; 69 String clazz = args[0]; 70 String [] newArgs = new String [numArgs - 1]; 71 System.arraycopy(args, 1, newArgs, 0, numArgs - 1); 72 Class target = Class.forName(clazz); 73 if (target == null) 74 throw new Exception ("Couldn't load class"); 75 Method mmeth = target.getMethod("main", new Class [] { String [].class }); 76 Object obj = target.newInstance(); 77 if (mmeth == null) 78 throw new Exception ("Couldn't find main()"); 79 start = new Date ().getTime(); 80 try { 81 mmeth.invoke(obj, new Object [] { newArgs }); 82 } finally { 83 } 84 } 85 86 static class MyShutdown extends Thread { 87 public void run() { 88 System.err.println("hey"); 89 System.err.flush(); 90 long elapsed = new Date ().getTime() - start; 91 System.out.println("Elapsed time : " + elapsed + "ms"); 92 } 93 } 94 } 95 | Popular Tags |