Browse Source

Merging in latest from upstream (CORE/base-third:refs/heads/feature/10.0)

* commit '352792c028fbf7160b37265f135de9a8b7399a0a':
  注释一下
  注释
  BI-29723 druid连接池生产线程阻塞
  BI-29723 druid连接池生产线程阻塞
  BI-29723 druid连接池生产连接线程阻塞
  增加tool.xsd
research/11.0
kerry 6 years ago
parent
commit
4af0be14a8
  1. 51
      fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java
  2. 13
      fine-spring/resources/META-INF/spring.schemas

51
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;
@ -607,16 +608,21 @@ 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);
}
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 +786,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
createAndLogThread();
createAndStartCreatorThread();
createAndStartDestroyThread();
createAndStartDetectThread();
initedLatch.await();
init = true;
@ -859,6 +865,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 +1540,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 +2214,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) {
//生产线程发生了切换,并且有线程在等待连接,需要主动唤醒生产线程,否则由getConnection方法来唤醒生产线程
if (!createConnectionThread.started && !destroyConnectionThread.started && notEmptyWaitThreadCount > 0) {
createConnectionThread.setStarted(true);
createConnectionThread.start();
destroyConnectionThread.setStarted(true);
destroyConnectionThread.start();
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException ignore) {
break;
}
}
}
}
public class DestroyConnectionThread extends Thread {
private volatile boolean started = true;

13
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

Loading…
Cancel
Save