mirror of
https://github.com/actiontech/dble.git
synced 2026-01-05 20:30:40 -06:00
[inner-2227] prevents 'connection-pool-evictor-thread' thread from exiting unexpectedly
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user