|
|
@ -602,7 +602,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
this.connectProperties = properties; |
|
|
|
this.connectProperties = properties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void createThreadChange() { |
|
|
|
private synchronized void doSomethingBeforeCreationThreadBreak() { |
|
|
|
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl(); |
|
|
|
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl(); |
|
|
|
createConnectionThread = new CreateConnectionThread(threadName); |
|
|
|
createConnectionThread = new CreateConnectionThread(threadName); |
|
|
|
createConnectionThread.setStarted(false); |
|
|
|
createConnectionThread.setStarted(false); |
|
|
@ -613,6 +613,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkThread() throws SQLException { |
|
|
|
private void checkThread() throws SQLException { |
|
|
|
|
|
|
|
if (createConnectionThread == null){ |
|
|
|
|
|
|
|
throw new IllegalStateException("createConnectionThread not start!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (destroyConnectionThread == null){ |
|
|
|
|
|
|
|
throw new IllegalStateException("destroyConnectionThread not start!"); |
|
|
|
|
|
|
|
} |
|
|
|
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { |
|
|
|
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { |
|
|
|
synchronized (this) {//线程安全问题,加个双检锁
|
|
|
|
synchronized (this) {//线程安全问题,加个双检锁
|
|
|
|
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { |
|
|
|
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) { |
|
|
@ -2119,6 +2125,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
} catch (InterruptedException e) { |
|
|
|
} catch (InterruptedException e) { |
|
|
|
lastCreateError = e; |
|
|
|
lastCreateError = e; |
|
|
|
lastErrorTimeMillis = System.currentTimeMillis(); |
|
|
|
lastErrorTimeMillis = System.currentTimeMillis(); |
|
|
|
|
|
|
|
DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
lock.unlock(); |
|
|
|
lock.unlock(); |
|
|
@ -2152,10 +2159,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
Thread.sleep(timeBetweenConnectErrorMillis); |
|
|
|
Thread.sleep(timeBetweenConnectErrorMillis); |
|
|
|
} catch (InterruptedException interruptEx) { |
|
|
|
} catch (InterruptedException ignore) { |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
DruidDataSource.this.createThreadChange(); |
|
|
|
DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (RuntimeException e) { |
|
|
|
} catch (RuntimeException e) { |
|
|
@ -2165,6 +2172,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
} catch (Error e) { |
|
|
|
} catch (Error e) { |
|
|
|
LOG.error("create connection error", e); |
|
|
|
LOG.error("create connection error", e); |
|
|
|
setFailContinuous(true); |
|
|
|
setFailContinuous(true); |
|
|
|
|
|
|
|
DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|