Skip to content

Commit

Permalink
代码精简
Browse files Browse the repository at this point in the history
  • Loading branch information
mek1986 authored and lizongbo committed May 9, 2024
1 parent c2e7e2b commit e08e92e
Showing 1 changed file with 13 additions and 35 deletions.
48 changes: 13 additions & 35 deletions core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,10 @@ public void init() throws SQLException {
this.id = DruidDriver.createDataSourceId();
if (this.id > 1) {
long delta = (this.id - 1) * 100000;
this.connectionIdSeedUpdater.addAndGet(this, delta);
this.statementIdSeedUpdater.addAndGet(this, delta);
this.resultSetIdSeedUpdater.addAndGet(this, delta);
this.transactionIdSeedUpdater.addAndGet(this, delta);
connectionIdSeedUpdater.addAndGet(this, delta);
statementIdSeedUpdater.addAndGet(this, delta);
resultSetIdSeedUpdater.addAndGet(this, delta);
transactionIdSeedUpdater.addAndGet(this, delta);
}

if (this.jdbcUrl != null) {
Expand Down Expand Up @@ -1140,7 +1140,6 @@ protected void createAndStartCreatorThread() {
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this);
createConnectionThread = new CreateConnectionThread(threadName);
createConnectionThread.start();
return;
}
}

Expand Down Expand Up @@ -1707,7 +1706,6 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce
LOG.debug("conn-direct_create ");
}

boolean discard;
final Lock lock = this.lock;
lock.lock();
try {
Expand All @@ -1719,16 +1717,12 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce
activePeakTime = System.currentTimeMillis();
}
break;
} else {
discard = true;
}
} finally {
lock.unlock();
}

if (discard) {
JdbcUtils.close(pyConnInfo.getPhysicalConnection());
}
JdbcUtils.close(pyConnInfo.getPhysicalConnection());
}
} finally {
createDirect = false;
Expand Down Expand Up @@ -1902,8 +1896,7 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce

holder.incrementUseCount();

DruidPooledConnection poolalbeConnection = new DruidPooledConnection(holder);
return poolalbeConnection;
return new DruidPooledConnection(holder);
}

public void handleConnectionException(
Expand Down Expand Up @@ -1996,7 +1989,7 @@ protected final void handleFatalError(

boolean emptySignalCalled = false;
if (requireDiscard) {
if (holder.statementTrace != null) {
if (holder != null && holder.statementTrace != null) {
holder.lock.lock();
try {
for (Statement stmt : holder.statementTrace) {
Expand All @@ -2012,7 +2005,7 @@ protected final void handleFatalError(
}

// holder.
LOG.error("{conn-" + holder.getConnectionId() + "} discard", error);
LOG.error("{conn-" + (holder != null ? holder.getConnectionId() : "null") + "} discard", error);

if (!emptySignalCalled && onFatalError && hasHolderDataSource) {
fatalErrorCountLock.lock();
Expand Down Expand Up @@ -2388,9 +2381,6 @@ private DruidConnectionHolder pollLast(long startTime, long expiredTime) throws
throw new DataSourceDisableException();
}

if (poolingCount == 0) {
continue;
}
}
} catch (InterruptedException ie) {
notEmpty.signal(); // propagate to non-interrupted thread
Expand Down Expand Up @@ -2716,11 +2706,7 @@ private void runInternal() {
return;
}

boolean emptyWait = true;

if (createError != null && poolingCount == 0) {
emptyWait = false;
}
boolean emptyWait = createError == null || poolingCount != 0;

if (emptyWait) {
// 必须存在线程等待,才创建连接
Expand Down Expand Up @@ -2885,13 +2871,9 @@ public void run() {
lastDiscardCount = discardCount;

try {
boolean emptyWait = true;

if (createError != null
&& poolingCount == 0
&& !discardChanged) {
emptyWait = false;
}
boolean emptyWait = createError == null
|| poolingCount != 0
|| discardChanged;

if (emptyWait
&& asyncInit && createCount < initialSize) {
Expand Down Expand Up @@ -4028,11 +4010,7 @@ static String sanitizedUrl(String url) {

private boolean isFillable(int toCount) {
int currentCount = this.poolingCount + this.activeCount;
if (currentCount >= toCount || currentCount >= this.maxActive) {
return false;
} else {
return true;
}
return currentCount < toCount && currentCount < this.maxActive;
}

public boolean isFull() {
Expand Down

0 comments on commit e08e92e

Please sign in to comment.