Skip to content

Commit a1d4bac

Browse files
committed
cleanup: remove deprecated TheadGroup methods
desc: The ThreadGroup class is an artificate of by-gone days. The ability to destroy a thread group and the concept of a destroyed thread group no longer exists. Several of the methods are null functions as well as marked for removal. This cleans up the usage of these methods.
1 parent 720775f commit a1d4bac

File tree

3 files changed

+17
-49
lines changed

3 files changed

+17
-49
lines changed

platform/core.execution/src/org/netbeans/core/execution/DefaultSysProcess.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,4 @@ public void run() {
101101
public String getName() {
102102
return name;
103103
}
104-
105-
/** destroy the thread group this process was handled from. Not that simple
106-
* as it seems, since the ThreadGroup can't be destroyed from inside.
107-
*/
108-
void destroyThreadGroup(ThreadGroup base) {
109-
new Thread(base, new Destroyer(group)).start();
110-
}
111-
private static class Destroyer implements Runnable {
112-
private final ThreadGroup group;
113-
Destroyer(ThreadGroup group) {
114-
this.group = group;
115-
}
116-
@Override public void run() {
117-
try {
118-
while (group.activeCount() > 0) {
119-
Thread.sleep(1000);
120-
}
121-
}
122-
catch (InterruptedException e) {
123-
Exceptions.printStackTrace(e);
124-
}
125-
if (!group.isDestroyed()) {
126-
try {
127-
group.destroy();
128-
} catch (IllegalThreadStateException x) {
129-
// #165302: destroyed some other way?
130-
}
131-
}
132-
}
133-
}
134-
135104
}

platform/core.execution/src/org/netbeans/core/execution/ExecutionEngine.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171

7272
/* table of window:threadgrp */
7373
private static final WindowTable wtable = new WindowTable();
74-
74+
7575
/** list of ExecutionListeners */
76-
private final HashSet<ExecutionListener> executionListeners = new HashSet<>();
76+
private final Set<ExecutionListener> executionListeners;
7777

7878
/** List of running executions */
7979
private final List<ExecutorTask> runningTasks = Collections.synchronizedList(new ArrayList<>(5));
@@ -87,6 +87,8 @@
8787
static final long serialVersionUID =9072488605180080803L;
8888

8989
public ExecutionEngine () {
90+
this.executionListeners = new HashSet<>();
91+
9092
/* SysIn is a class that redirects System.in of some running task to
9193
a window (probably OutWindow).
9294
SysOut/Err are classes that redirect out/err to the window
@@ -134,7 +136,6 @@ public String getRunningTaskName( ExecutorTask task ) {
134136
@Override
135137
public ExecutorTask execute(String name, Runnable run, final InputOutput inout) {
136138
TaskThreadGroup g = new TaskThreadGroup(base, "exec_" + name + "_" + number); // NOI18N
137-
g.setDaemon(true);
138139
ExecutorTaskImpl task = new ExecutorTaskImpl();
139140
synchronized (task.lock) {
140141
try {
@@ -192,25 +193,30 @@ protected final PermissionCollection createPermissions(CodeSource cs, InputOutpu
192193

193194
/** fires event that notifies about new process */
194195
protected final void fireExecutionStarted (ExecutionEvent ev) {
195-
runningTasks.add( ev.getProcess() );
196-
@SuppressWarnings("unchecked")
197-
Iterator<ExecutionListener> iter = ((HashSet<ExecutionListener>) executionListeners.clone()).iterator();
196+
runningTasks.add(ev.getProcess());
197+
198+
Iterator<ExecutionListener> iter;
199+
synchronized (executionListeners) {
200+
iter = (new HashSet<>(executionListeners)).iterator();
201+
}
198202
while (iter.hasNext()) {
199203
ExecutionListener l = iter.next();
200204
l.startedExecution(ev);
201205
}
202206
}
203207

204208
/** fires event that notifies about the end of a process */
205-
protected final void fireExecutionFinished (ExecutionEvent ev) {
206-
runningTasks.remove( ev.getProcess() );
207-
@SuppressWarnings("unchecked")
208-
Iterator<ExecutionListener> iter = ((HashSet<ExecutionListener>) executionListeners.clone()).iterator();
209+
protected final void fireExecutionFinished(ExecutionEvent ev) {
210+
runningTasks.remove(ev.getProcess());
211+
212+
Iterator<ExecutionListener> iter;
213+
synchronized (executionListeners) {
214+
iter = (new HashSet<>(executionListeners)).iterator();
215+
}
209216
while (iter.hasNext()) {
210217
ExecutionListener l = iter.next();
211218
l.finishedExecution(ev);
212219
}
213-
ev.getProcess().destroyThreadGroup(base);
214220
}
215221

216222
static void putWindow(java.awt.Window w, TaskThreadGroup tg) {
@@ -296,5 +302,4 @@ public void close() throws IOException {
296302
static PrintStream createPrintStream(boolean stdOut) {
297303
return new WriterPrintStream(new SysOut(stdOut), stdOut);
298304
}
299-
300305
}

platform/openide.util/src/org/openide/util/RequestProcessor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,20 +1892,14 @@ static Processor get() {
18921892
return proc;
18931893
}
18941894
} else {
1895-
assert checkAccess(TOP_GROUP.getTopLevelThreadGroup());
18961895
Processor proc = POOL.pop();
18971896
proc.idle = false;
1898-
18991897
return proc;
19001898
}
19011899
}
19021900
newP = new Processor();
19031901
}
19041902
}
1905-
private static boolean checkAccess(ThreadGroup g) throws SecurityException {
1906-
g.checkAccess();
1907-
return true;
1908-
}
19091903

19101904
/** A way of returning a Processor to the inactive pool.
19111905
*

0 commit comments

Comments
 (0)