From e51101407b027a06ee5b1ce450d5b783c8b1e07f Mon Sep 17 00:00:00 2001 From: anchore Date: Wed, 22 Aug 2018 17:45:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0tool.xsd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fine-spring/resources/META-INF/spring.schemas | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fine-spring/resources/META-INF/spring.schemas b/fine-spring/resources/META-INF/spring.schemas index 7f5a7575b..dc698ce0d 100644 --- a/fine-spring/resources/META-INF/spring.schemas +++ b/fine-spring/resources/META-INF/spring.schemas @@ -4,6 +4,7 @@ http\://www.springframework.org/schema/context/spring-context-3.1.xsd=com/fr/thi http\://www.springframework.org/schema/context/spring-context-3.2.xsd=com/fr/third/springframework/context/config/spring-context-3.2.xsd http\://www.springframework.org/schema/context/spring-context-4.0.xsd=com/fr/third/springframework/context/config/spring-context-4.0.xsd http\://www.springframework.org/schema/context/spring-context.xsd=com/fr/third/springframework/context/config/spring-context-4.0.xsd + http\://www.springframework.org/schema/jee/spring-jee-2.0.xsd=com/fr/third/springframework/ejb/config/spring-jee-2.0.xsd http\://www.springframework.org/schema/jee/spring-jee-2.5.xsd=com/fr/third/springframework/ejb/config/spring-jee-2.5.xsd http\://www.springframework.org/schema/jee/spring-jee-3.0.xsd=com/fr/third/springframework/ejb/config/spring-jee-3.0.xsd @@ -11,6 +12,7 @@ http\://www.springframework.org/schema/jee/spring-jee-3.1.xsd=com/fr/third/sprin http\://www.springframework.org/schema/jee/spring-jee-3.2.xsd=com/fr/third/springframework/ejb/config/spring-jee-3.2.xsd http\://www.springframework.org/schema/jee/spring-jee-4.0.xsd=com/fr/third/springframework/ejb/config/spring-jee-4.0.xsd http\://www.springframework.org/schema/jee/spring-jee.xsd=com/fr/third/springframework/ejb/config/spring-jee-4.0.xsd + http\://www.springframework.org/schema/lang/spring-lang-2.0.xsd=com/fr/third/springframework/scripting/config/spring-lang-2.0.xsd http\://www.springframework.org/schema/lang/spring-lang-2.5.xsd=com/fr/third/springframework/scripting/config/spring-lang-2.5.xsd http\://www.springframework.org/schema/lang/spring-lang-3.0.xsd=com/fr/third/springframework/scripting/config/spring-lang-3.0.xsd @@ -18,15 +20,18 @@ http\://www.springframework.org/schema/lang/spring-lang-3.1.xsd=com/fr/third/spr http\://www.springframework.org/schema/lang/spring-lang-3.2.xsd=com/fr/third/springframework/scripting/config/spring-lang-3.2.xsd http\://www.springframework.org/schema/lang/spring-lang-4.0.xsd=com/fr/third/springframework/scripting/config/spring-lang-4.0.xsd http\://www.springframework.org/schema/lang/spring-lang.xsd=com/fr/third/springframework/scripting/config/spring-lang-4.0.xsd + http\://www.springframework.org/schema/task/spring-task-3.0.xsd=com/fr/third/springframework/scheduling/config/spring-task-3.0.xsd http\://www.springframework.org/schema/task/spring-task-3.1.xsd=com/fr/third/springframework/scheduling/config/spring-task-3.1.xsd http\://www.springframework.org/schema/task/spring-task-3.2.xsd=com/fr/third/springframework/scheduling/config/spring-task-3.2.xsd http\://www.springframework.org/schema/task/spring-task-4.0.xsd=com/fr/third/springframework/scheduling/config/spring-task-4.0.xsd http\://www.springframework.org/schema/task/spring-task.xsd=com/fr/third/springframework/scheduling/config/spring-task-4.0.xsd + http\://www.springframework.org/schema/cache/spring-cache-3.1.xsd=com/fr/third/springframework/cache/config/spring-cache-3.1.xsd http\://www.springframework.org/schema/cache/spring-cache-3.2.xsd=com/fr/third/springframework/cache/config/spring-cache-3.2.xsd http\://www.springframework.org/schema/cache/spring-cache-4.0.xsd=com/fr/third/springframework/cache/config/spring-cache-4.0.xsd http\://www.springframework.org/schema/cache/spring-cache.xsd=com/fr/third/springframework/cache/config/spring-cache-4.0.xsd + http\://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-3.0.xsd http\://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-3.1.xsd http\://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-3.2.xsd @@ -40,3 +45,11 @@ http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=com/fr/third/s http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-3.2.xsd http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-4.0.xsd http\://www.springframework.org/schema/beans/spring-beans.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-4.0.xsd + +http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-2.0.xsd +http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-2.5.xsd +http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-3.0.xsd +http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-3.1.xsd +http\://www.springframework.org/schema/tool/spring-tool-3.2.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-3.2.xsd +http\://www.springframework.org/schema/tool/spring-tool-4.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-4.0.xsd +http\://www.springframework.org/schema/tool/spring-tool.xsd=com/fr/third/springframework/beans/factory/xml/spring-tool-4.0.xsd From 8f313c4857467a11624b997a25b6cc9582db0b47 Mon Sep 17 00:00:00 2001 From: abel Date: Wed, 29 Aug 2018 14:32:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?BI-29723=20druid=E8=BF=9E=E6=8E=A5=E6=B1=A0?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=BF=9E=E6=8E=A5=E7=BA=BF=E7=A8=8B=E9=98=BB?= =?UTF-8?q?=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/druid/pool/DruidDataSource.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 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 8fd1f3937..f9a79e459 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 @@ -139,6 +139,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat private DestroyTask destroyTask; private CreateConnectionThread createConnectionThread; + private PeriodDetectionThread periodDetectionThread; private DestroyConnectionThread destroyConnectionThread; private LogStatsThread logStatsThread; private int createTaskCount; @@ -613,10 +614,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat } private void checkThread() throws SQLException { - if (createConnectionThread == null){ + if (createConnectionThread == null) { throw new IllegalStateException("createConnectionThread not start!"); } - if (destroyConnectionThread == null){ + if (destroyConnectionThread == null) { throw new IllegalStateException("destroyConnectionThread not start!"); } if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { @@ -780,7 +781,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat createAndLogThread(); createAndStartCreatorThread(); createAndStartDestroyThread(); - + createAndStartDetectThread(); initedLatch.await(); init = true; @@ -859,6 +860,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat initedLatch.countDown(); } + private void createAndStartDetectThread() { + if(createScheduler == null){ + String threadName = "Druid-ConnectionPool-Detection-" + System.identityHashCode(this) + this.getUrl(); + periodDetectionThread = new PeriodDetectionThread(threadName); + periodDetectionThread.start(); + } + } + /** * load filters from SPI ServiceLoader @@ -1526,7 +1535,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat if (destroyConnectionThread != null) { destroyConnectionThread.interrupt(); } - + if (periodDetectionThread != null){ + periodDetectionThread.interrupt(); + } if (destroySchedulerFuture != null) { destroySchedulerFuture.cancel(true); } @@ -2198,6 +2209,33 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat this.started = started; } } + //周期性检查生产线程状态,因为在终止生产线程的时候,为了不让生产线程疯狂重试数据库,只是生成了一个生产线程,但是并没有start,需要一个守护线程 + //周期性检查线程状态,帮助其启动。 + private class PeriodDetectionThread extends Thread { + public PeriodDetectionThread(String name) { + super(name); + this.setDaemon(true); + } + + public void run() { + while(true) { + synchronized (DruidDataSource.this) { + //生产线程发生了切换,并且有线程在等待连接,需要主动唤醒生产线程,否则由 + if (!createConnectionThread.started && !destroyConnectionThread.started && notEmptyWaitThreadCount > 0) { + createConnectionThread.setStarted(true); + createConnectionThread.start(); + destroyConnectionThread.setStarted(true); + destroyConnectionThread.start(); + } + } + try { + Thread.sleep(timeBetweenConnectErrorMillis); + } catch (InterruptedException ignore) { + break; + } + } + } + } public class DestroyConnectionThread extends Thread { private volatile boolean started = true; From a1344a7d406f310f9814fce52633d1772b98af28 Mon Sep 17 00:00:00 2001 From: abel Date: Wed, 29 Aug 2018 14:37:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?BI-29723=20druid=E8=BF=9E=E6=8E=A5=E6=B1=A0?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=BA=BF=E7=A8=8B=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/third/alibaba/druid/pool/DruidDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f9a79e459..a9f783bfe 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 @@ -2229,7 +2229,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat } } try { - Thread.sleep(timeBetweenConnectErrorMillis); + Thread.sleep(30000); } catch (InterruptedException ignore) { break; } From a9aed9e19281ca2ec9cbc96aa3f178c91850f375 Mon Sep 17 00:00:00 2001 From: abel Date: Wed, 29 Aug 2018 16:43:35 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/alibaba/druid/pool/DruidDataSource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 a9f783bfe..ef1481c9d 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 @@ -608,6 +608,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat createConnectionThread = new CreateConnectionThread(threadName); createConnectionThread.setStarted(false); String destroyName = "Druid-ConnectionPool-Destroy-" + System.identityHashCode(this) + this.getUrl(); + if (destroyConnectionThread != null) { + if (!destroyConnectionThread.isInterrupted()) { + destroyConnectionThread.interrupt(); + } + } destroyConnectionThread = new DestroyConnectionThread(destroyName); destroyConnectionThread.setStarted(false); initedLatch = new CountDownLatch(2); @@ -2220,7 +2225,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat public void run() { while(true) { synchronized (DruidDataSource.this) { - //生产线程发生了切换,并且有线程在等待连接,需要主动唤醒生产线程,否则由 + //生产线程发生了切换,并且有线程在等待连接,需要主动唤醒生产线程,否则由getConnection方法来唤醒生产线程 if (!createConnectionThread.started && !destroyConnectionThread.started && notEmptyWaitThreadCount > 0) { createConnectionThread.setStarted(true); createConnectionThread.start();