Browse Source

Merge pull request #85 in CORE/base-third from ~ABEL.CHEN/base-third:release/9.0 to release/9.0

* commit '9a756e4b3b684064796693ebbb6da09aa14c1a80':
  生产连接的线程切换时,加个双检锁,确保线程状态准确
release/9.0
abel.chen 6 years ago
parent
commit
ee4374c8cb
  1. 20
      fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java

20
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 { private void checkThread() throws SQLException {
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
createConnectionThread.setStarted(true); synchronized (this) {//线程安全问题,加个双检锁
createConnectionThread.start(); if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
destroyConnectionThread.setStarted(true); createConnectionThread.setStarted(true);
destroyConnectionThread.start(); createConnectionThread.start();
try { destroyConnectionThread.setStarted(true);
initedLatch.await(); destroyConnectionThread.start();
} catch (InterruptedException e) { try {
throw new SQLException(e.getMessage(), e); initedLatch.await();
} catch (InterruptedException e) {
throw new SQLException(e.getMessage(), e);
}
}
} }
} }
} }

Loading…
Cancel
Save