Commit 6dad6600 authored by bryn's avatar bryn Committed by Brandon Williams

CASSANDRA-15677 Add shutdown to JMX thread pool to avoid metaspace errors...

CASSANDRA-15677 Add shutdown to JMX thread pool to avoid metaspace errors associated with thread leaks. There are still other thread shutdown issues remaining, but this seems to be the most serious one.
parent 58141308
......@@ -18,9 +18,11 @@
package org.apache.cassandra.utils.progress.jmx;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.cassandra.concurrent.NamedThreadFactory;
* Holds dedicated executor for JMX event handling. Events will internally queued by ArrayNotificationBuffer,
* synchronized by an exclusive write lock, which makes a shared single thread executor desirable.
......@@ -30,6 +32,6 @@ public final class JMXBroadcastExecutor
private JMXBroadcastExecutor() { }
public final static Executor executor = Executors.newSingleThreadExecutor();
public final static ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("JMX"));
......@@ -667,9 +667,21 @@ public abstract class AbstractCluster<I extends IInstance> implements ICluster<I
previousHandler = null;
private void checkForThreadLeaks()
//This is an alternate version of the thread leak check that just checks to see if any threads are still alive
// with the context classloader.
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();>t.getContextClassLoader() instanceof InstanceClassLoader).forEach(t->{
throw new RuntimeException("Unterminated thread detected " + t.getName() + " in group " + t.getThreadGroup().getName());
// We do not want this check to run every time until we fix problems with tread stops
private void withThreadLeakCheck(List<Future<?>> futures)
......@@ -108,6 +108,7 @@ import org.apache.cassandra.utils.JVMStabilityInspector;
import org.apache.cassandra.utils.Throwables;
import org.apache.cassandra.utils.concurrent.Ref;
import org.apache.cassandra.utils.memory.BufferPool;
import org.apache.cassandra.utils.progress.jmx.JMXBroadcastExecutor;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
......@@ -566,6 +567,9 @@ public class Instance extends IsolatedExecutor implements IInvokableInstance
() -> Stage.shutdownAndWait(1L, MINUTES),
() -> SharedExecutorPool.SHARED.shutdownAndWait(1L, MINUTES)
error = parallelRun(error, executor,
() -> shutdownAndWait(Collections.singletonList(JMXBroadcastExecutor.executor))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment