diff --git a/platform/core.execution/src/org/netbeans/core/execution/DefaultSysProcess.java b/platform/core.execution/src/org/netbeans/core/execution/DefaultSysProcess.java index 6d2b6c3d4509..d11e169bdd02 100644 --- a/platform/core.execution/src/org/netbeans/core/execution/DefaultSysProcess.java +++ b/platform/core.execution/src/org/netbeans/core/execution/DefaultSysProcess.java @@ -101,35 +101,4 @@ public void run() { public String getName() { return name; } - - /** destroy the thread group this process was handled from. Not that simple - * as it seems, since the ThreadGroup can't be destroyed from inside. - */ - void destroyThreadGroup(ThreadGroup base) { - new Thread(base, new Destroyer(group)).start(); - } - private static class Destroyer implements Runnable { - private final ThreadGroup group; - Destroyer(ThreadGroup group) { - this.group = group; - } - @Override public void run() { - try { - while (group.activeCount() > 0) { - Thread.sleep(1000); - } - } - catch (InterruptedException e) { - Exceptions.printStackTrace(e); - } - if (!group.isDestroyed()) { - try { - group.destroy(); - } catch (IllegalThreadStateException x) { - // #165302: destroyed some other way? - } - } - } - } - } diff --git a/platform/core.execution/src/org/netbeans/core/execution/ExecutionEngine.java b/platform/core.execution/src/org/netbeans/core/execution/ExecutionEngine.java index 3ae04281f636..f554209df38e 100644 --- a/platform/core.execution/src/org/netbeans/core/execution/ExecutionEngine.java +++ b/platform/core.execution/src/org/netbeans/core/execution/ExecutionEngine.java @@ -71,9 +71,9 @@ /* table of window:threadgrp */ private static final WindowTable wtable = new WindowTable(); - + /** list of ExecutionListeners */ - private final HashSet executionListeners = new HashSet<>(); + private final Set executionListeners; /** List of running executions */ private final List runningTasks = Collections.synchronizedList(new ArrayList<>(5)); @@ -87,6 +87,8 @@ static final long serialVersionUID =9072488605180080803L; public ExecutionEngine () { + this.executionListeners = new HashSet<>(); + /* SysIn is a class that redirects System.in of some running task to a window (probably OutWindow). SysOut/Err are classes that redirect out/err to the window @@ -134,7 +136,6 @@ public String getRunningTaskName( ExecutorTask task ) { @Override public ExecutorTask execute(String name, Runnable run, final InputOutput inout) { TaskThreadGroup g = new TaskThreadGroup(base, "exec_" + name + "_" + number); // NOI18N - g.setDaemon(true); ExecutorTaskImpl task = new ExecutorTaskImpl(); synchronized (task.lock) { try { @@ -192,9 +193,12 @@ protected final PermissionCollection createPermissions(CodeSource cs, InputOutpu /** fires event that notifies about new process */ protected final void fireExecutionStarted (ExecutionEvent ev) { - runningTasks.add( ev.getProcess() ); - @SuppressWarnings("unchecked") - Iterator iter = ((HashSet) executionListeners.clone()).iterator(); + runningTasks.add(ev.getProcess()); + + Iterator iter; + synchronized (executionListeners) { + iter = (new HashSet<>(executionListeners)).iterator(); + } while (iter.hasNext()) { ExecutionListener l = iter.next(); l.startedExecution(ev); @@ -202,15 +206,17 @@ protected final void fireExecutionStarted (ExecutionEvent ev) { } /** fires event that notifies about the end of a process */ - protected final void fireExecutionFinished (ExecutionEvent ev) { - runningTasks.remove( ev.getProcess() ); - @SuppressWarnings("unchecked") - Iterator iter = ((HashSet) executionListeners.clone()).iterator(); + protected final void fireExecutionFinished(ExecutionEvent ev) { + runningTasks.remove(ev.getProcess()); + + Iterator iter; + synchronized (executionListeners) { + iter = (new HashSet<>(executionListeners)).iterator(); + } while (iter.hasNext()) { ExecutionListener l = iter.next(); l.finishedExecution(ev); } - ev.getProcess().destroyThreadGroup(base); } static void putWindow(java.awt.Window w, TaskThreadGroup tg) { @@ -296,5 +302,4 @@ public void close() throws IOException { static PrintStream createPrintStream(boolean stdOut) { return new WriterPrintStream(new SysOut(stdOut), stdOut); } - } diff --git a/platform/openide.util/src/org/openide/util/RequestProcessor.java b/platform/openide.util/src/org/openide/util/RequestProcessor.java index eb91719c57bb..d1f8e2ee400e 100644 --- a/platform/openide.util/src/org/openide/util/RequestProcessor.java +++ b/platform/openide.util/src/org/openide/util/RequestProcessor.java @@ -1892,20 +1892,14 @@ static Processor get() { return proc; } } else { - assert checkAccess(TOP_GROUP.getTopLevelThreadGroup()); Processor proc = POOL.pop(); proc.idle = false; - return proc; } } newP = new Processor(); } } - private static boolean checkAccess(ThreadGroup g) throws SecurityException { - g.checkAccess(); - return true; - } /** A way of returning a Processor to the inactive pool. *