Browse Source

线程切换,多线程同步问题

final/10.0.3
abel 6 years ago
parent
commit
68085657b2
  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

@ -614,14 +614,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);
}
}
}
}
}

Loading…
Cancel
Save