1 19 20 package org.netbeans.core.execution; 21 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 import org.openide.execution.ExecutorTask; 25 import org.openide.util.Exceptions; 26 import org.openide.windows.InputOutput; 27 28 32 final class DefaultSysProcess extends ExecutorTask { 33 34 35 static int processCount; 36 37 private final TaskThreadGroup group; 38 39 private boolean destroyed = false; 40 41 private final InputOutput io; 42 43 private final String name; 44 45 48 public DefaultSysProcess(Runnable run, TaskThreadGroup grp, InputOutput io, String name) { 49 super(run); 50 group = grp; 51 this.io = io; 52 this.name = name; 53 } 54 55 56 public synchronized void stop() { 57 58 if (destroyed) return; 59 destroyed = true; 60 try { 61 group.interrupt(); 62 group.stop(); 63 group.getRunClassThread().waitForEnd(); 64 } catch (InterruptedException e) { 65 Logger.getLogger(DefaultSysProcess.class.getName()).log(Level.WARNING, null, e); 66 } 67 ExecutionEngine.closeGroup(group); 68 group.kill(); notifyFinished(); 70 } 71 72 75 public int result() { 76 try { 79 group.waitFor(); 80 } catch (InterruptedException e) { 81 return 4; } 83 notifyFinished(); 84 return 0; 85 } 86 87 88 public InputOutput getInputOutput() { 89 return io; 90 } 91 92 public void run() { 93 } 94 95 public String getName() { 96 return name; 97 } 98 99 102 void destroyThreadGroup(ThreadGroup base) { 103 new Thread (base, 104 new Runnable () { 105 106 public void run() { 107 try { 108 while (group.activeCount() > 0) { 109 Thread.sleep(1000); 110 } 111 } 112 catch (InterruptedException e) { 113 Exceptions.printStackTrace(e); 114 } 115 if (!group.isDestroyed()) 116 group.destroy(); 117 } 118 }).start(); 119 } 120 } 121 | Popular Tags |