[inner-2227] prevents 'connection-pool-evictor-thread' thread from exiting unexpectedly

This commit is contained in:
wenyh
2023-05-18 15:58:11 +08:00
committed by wenyh1
parent c0cfb4d1a6
commit dc7a75bb07
2 changed files with 15 additions and 6 deletions

View File

@@ -520,6 +520,8 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
// Try to maintain minimum connections
fillPool();
} catch (Throwable t) {
LOGGER.warn("Evictor.run happen Throwable: ", t);
} finally {
// Restore the previous CCL
Thread.currentThread().setContextClassLoader(savedClassLoader);
@@ -533,6 +535,7 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
*/
void setScheduledFuture(final ScheduledFuture<?> scheduledFuture) {
this.scheduledFuture = scheduledFuture;
EvictionTimer.getAliveEvictor().add(scheduledFuture);
}
/**
@@ -540,6 +543,7 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
*/
void cancel() {
scheduledFuture.cancel(false);
EvictionTimer.getAliveEvictor().remove(scheduledFuture);
}
}
}

View File

@@ -1,19 +1,20 @@
package com.actiontech.dble.backend.pool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
final class EvictionTimer {
private static final Logger LOGGER = LoggerFactory.getLogger(EvictionTimer.class);
/**
* Executor instance
*/
private static ScheduledThreadPoolExecutor executor; //@GuardedBy("EvictionTimer.class")
private static ConcurrentLinkedQueue aliveEvictor = new ConcurrentLinkedQueue();
/**
* Prevents instantiation
*/
@@ -21,6 +22,9 @@ final class EvictionTimer {
// Hide the default constructor
}
public static ConcurrentLinkedQueue getAliveEvictor() {
return aliveEvictor;
}
/**
* @since 2.4.3
@@ -68,8 +72,9 @@ final class EvictionTimer {
if (evictor != null) {
evictor.cancel();
}
if (executor != null && executor.getQueue().isEmpty()) {
if (executor != null && aliveEvictor.isEmpty()) {
executor.shutdown();
LOGGER.info("EvictionTimer executor shutdown");
try {
executor.awaitTermination(timeout, unit);
} catch (final InterruptedException e) {