diff --git a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java index 3d8a6b6..5a70548 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. */ @@ -1861,11 +1861,16 @@ 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; } } } finally {