From 9a756e4b3b684064796693ebbb6da09aa14c1a80 Mon Sep 17 00:00:00 2001 From: abel Date: Mon, 6 Aug 2018 11:19:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=BF=9E=E6=8E=A5=E7=9A=84?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E5=88=87=E6=8D=A2=E6=97=B6=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E4=B8=AA=E5=8F=8C=E6=A3=80=E9=94=81=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E7=8A=B6=E6=80=81=E5=87=86=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/druid/pool/DruidDataSource.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java index edae35120..77af154a0 100644 --- a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java +++ b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java @@ -620,14 +620,18 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat private void checkThread() throws SQLException { if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { - createConnectionThread.setStarted(true); - createConnectionThread.start(); - destroyConnectionThread.setStarted(true); - destroyConnectionThread.start(); - try { - initedLatch.await(); - } catch (InterruptedException e) { - throw new SQLException(e.getMessage(), e); + synchronized (this) {//线程安全问题,加个双检锁 + if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { + createConnectionThread.setStarted(true); + createConnectionThread.start(); + destroyConnectionThread.setStarted(true); + destroyConnectionThread.start(); + try { + initedLatch.await(); + } catch (InterruptedException e) { + throw new SQLException(e.getMessage(), e); + } + } } } }