diff --git a/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java b/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java index 69ca361e4e..68f9d6349f 100644 --- a/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java +++ b/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java @@ -120,8 +120,7 @@ public class DruidDataSource extends DruidAbstractDataSource private volatile ScheduledFuture destroySchedulerFuture; private DestroyTask destroyTask; - private volatile Future createSchedulerFuture; - + private final Map> createSchedulerFutures = new ConcurrentHashMap<>(16); private CreateConnectionThread createConnectionThread; private DestroyConnectionThread destroyConnectionThread; private LogStatsThread logStatsThread; @@ -1077,7 +1076,7 @@ private void submitCreateTask(boolean initTask) { createTasks = array; } - this.createSchedulerFuture = createScheduler.submit(task); + this.createSchedulerFutures.put(task, createScheduler.submit(task)); } private boolean clearCreateTask(long taskId) { @@ -2221,7 +2220,7 @@ public void close() { destroyConnectionThread.interrupt(); } - if (createSchedulerFuture != null) { + for (Future createSchedulerFuture : createSchedulerFutures.values()) { createSchedulerFuture.cancel(true); } @@ -2809,7 +2808,8 @@ private void runInternal() { return; } - createSchedulerFuture = createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS); + createSchedulerFutures.put(this, + createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS)); return; } } catch (SQLException e) { @@ -2849,7 +2849,8 @@ private void runInternal() { return; } - createSchedulerFuture = createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS); + createSchedulerFutures.put(this, + createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS)); return; } } catch (RuntimeException e) {