From 4ae8fd9266e2f67a0c4ce3b48356355c6286f0dc Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 2 Aug 2021 09:58:27 +0100 Subject: [PATCH 1/2] Set AccessControlContext to null on termination to release captured classloaders --- src/main/java/org/jboss/threads/EnhancedQueueExecutor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java index 3d8a6b6..171a17f 100644 --- a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java +++ b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java @@ -191,7 +191,7 @@ public final class EnhancedQueueExecutor extends EnhancedQueueExecutorBase6 impl * The access control context of the creating thread. * Will be set to null when the MBean is not registered. */ - private final AccessControlContext acc; + private volatile AccessControlContext acc; /** * The context handler for the user-defined context. */ @@ -1867,6 +1867,7 @@ void completeTermination() { intr = intr || Thread.interrupted(); doPrivileged(new MBeanUnregisterAction(handle), acc); } + this.acc = null; } } finally { if (intr) { From b3cb132e0fb4d503ca44a1bac62d0e3bf2c8c5dc Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 5 Aug 2021 10:53:13 +0100 Subject: [PATCH 2/2] Maintain the DISABLE_MBEAN hint for GraalVM native images --- .../org/jboss/threads/EnhancedQueueExecutor.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java index 171a17f..5a70548 100644 --- a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java +++ b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java @@ -1861,13 +1861,17 @@ void completeTermination() { waiters = waiters.getNext(); } tail.setNext(TERMINATE_COMPLETE); - if (this.acc != null) { - final Object handle = this.handle; - if (handle != null) { - intr = intr || Thread.interrupted(); - doPrivileged(new MBeanUnregisterAction(handle), acc); + if (!DISABLE_MBEAN) { + //The check for DISABLE_MBEAN is redundant as acc would be null, + //but GraalVM needs the hint so to not make JMX reachable. + if (this.acc != null) { + final Object handle = this.handle; + if (handle != null) { + intr = intr || Thread.interrupted(); + doPrivileged(new MBeanUnregisterAction(handle), acc); + } + this.acc = null; } - this.acc = null; } } finally { if (intr) {