Skip to content

Commit

Permalink
8289616: Drop use of Thread.stop in AppContext
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, iris, azvegint
  • Loading branch information
prrace committed Aug 16, 2022
1 parent e44e3f0 commit 01b87ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 111 deletions.
41 changes: 7 additions & 34 deletions src/java.desktop/share/classes/sun/awt/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ public static boolean isMainContext(AppContext ctx) {
*/
@SuppressWarnings({"deprecation", "removal"})
public void dispose() throws IllegalThreadStateException {
System.err.println(
"""
WARNING: sun.awt.AppContext.dispose() no longer stops threads.
Additionally AppContext will be removed in a future release.
Remove all uses of this internal class as soon as possible.
There is no replacement.
""");
// Check to be sure that the current Thread isn't in this AppContext
if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
throw new IllegalThreadStateException(
Expand Down Expand Up @@ -502,33 +509,6 @@ public Void run() {
} catch (InterruptedException e) { }
}

// Then, we stop any remaining Threads
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread[] threads;
int len, threadCount;
do {
len = threadGroup.activeCount() + 4;
threads = new Thread[len];
threadCount = threadGroup.enumerate(threads);
} while (threadCount == len);
for (int i = 0; i < threadCount; i++) {
threads[i].stop();
}
return null;
});

// Next, we sleep 10ms at a time, waiting for all of the active
// Threads in the ThreadGroup to die.

startTime = System.currentTimeMillis();
endTime = startTime + THREAD_INTERRUPT_TIMEOUT;
while ((this.threadGroup.activeCount() > 0) &&
(System.currentTimeMillis() < endTime)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
}

// Next, we remove this and all subThreadGroups from threadGroup2appContext
int numSubGroups = this.threadGroup.activeGroupCount();
if (numSubGroups > 0) {
Expand All @@ -542,13 +522,6 @@ public Void run() {

threadAppContext.set(null);

// Finally, we destroy the ThreadGroup entirely.
try {
this.threadGroup.destroy();
} catch (IllegalThreadStateException e) {
// Fired if not all the Threads died, ignore it and proceed
}

synchronized (table) {
this.table.clear(); // Clear out the Hashtable to ease garbage collection
}
Expand Down

This file was deleted.

1 comment on commit 01b87ba

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.