1 19 20 package org.netbeans.core.execution; 21 22 23 28 final class TaskThreadGroup extends ThreadGroup { 29 30 private Object TIMER = new Object (); 31 32 33 private boolean runClassThreadOut = false; 34 35 36 private boolean finalizable; 37 38 39 private boolean dead; 40 41 42 private RunClassThread runClassThread; 43 44 TaskThreadGroup(ThreadGroup parent, String name) { 45 super(parent, name); 46 47 dead = false; 48 } 49 50 56 private boolean isProcessDead(boolean inside) { 57 58 synchronized (this) { 59 if (dead) { 60 return true; 61 } 62 63 if (! finalizable) { 65 return false; 66 } 67 68 int count; 69 count = activeCount(); 70 71 82 if (count > 1) { 83 int active = 0; 84 Thread [] threads = 85 new Thread [count]; 86 enumerate(threads); 87 for (int i = threads.length; --i >= 0;) { 88 if ((threads[i] != null) && 90 (threads[i].isAlive() && !threads[i].isDaemon()) 91 ) { 92 if (++active > 1) { 93 return false; 94 } 95 } 96 } 97 count = active; 98 } 99 100 if (ExecutionEngine.hasWindows(this)) { 101 return false; 102 } 103 104 if (count == 0) { 105 return true; } 107 108 if (inside) { 110 return true; 111 } 112 return false; 113 } 114 } 115 116 118 void waitFor() throws InterruptedException { 119 boolean inside = Thread.currentThread() instanceof RunClassThread; 120 synchronized (TIMER) { 121 try { 122 while (! isProcessDead(inside)) { 123 TIMER.wait(1000); 124 } 125 } finally { 126 TIMER.notifyAll(); 127 synchronized(this) { 128 dead = true; 129 } 130 } 131 } 132 } 133 134 135 synchronized void setFinalizable() { 136 finalizable = true; 137 } 138 139 140 void kill() { 141 synchronized (TIMER) { 142 if (! dead) { 143 dead = true; 144 TIMER.notifyAll(); 145 try { 146 TIMER.wait(3000); 147 } catch (InterruptedException e) { 148 } 149 } 150 } 151 } 152 153 public void setRunClassThread(RunClassThread t) { 154 runClassThread = t; 155 } 156 157 public RunClassThread getRunClassThread() { 158 return runClassThread; 159 } 160 } 161 | Popular Tags |