mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
removeAbandoned log增加 ownerThread和它当前的状态和堆栈
This commit is contained in:
@@ -36,6 +36,15 @@
|
||||
<url>file://${basedir}/lib/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>oschina</id>
|
||||
<name>oschina Repository</name>
|
||||
<layout>default</layout>
|
||||
<url>http://maven.oschina.net/content/repositories/public</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<!--
|
||||
@@ -108,6 +117,7 @@
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -119,6 +129,7 @@
|
||||
<includes>
|
||||
<include>**/bvt/**/*.java</include>
|
||||
</includes>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -293,13 +304,6 @@
|
||||
</file>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>jconsole</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${java.home}/../Classes/jconsole.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
|
||||
@@ -463,12 +467,17 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>11.2.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.oracle</groupId>-->
|
||||
<!--<artifactId>ojdbc6</artifactId>-->
|
||||
<!--<version>11.2.0.3</version>-->
|
||||
<!--<scope>provided</scope>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.guoyukun.jdbc</groupId>
|
||||
<artifactId>oracle-ojdbc6</artifactId>
|
||||
<version>11.2.0.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
@@ -518,14 +527,14 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>proxool</groupId>
|
||||
<groupId>com.cloudhopper.proxool</groupId>
|
||||
<artifactId>proxool</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>proxool</groupId>
|
||||
<artifactId>proxool-cglib</artifactId>
|
||||
<groupId>com.cloudhopper.proxool</groupId>
|
||||
<artifactId>proxool-cglib</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
@@ -575,8 +584,7 @@
|
||||
<dependency>
|
||||
<groupId>com.taobao.tbdatasource</groupId>
|
||||
<artifactId>tbdatasource</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<scope>test</scope>
|
||||
<version>3.0.1.5.taobaocode</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>jboss</groupId>
|
||||
@@ -610,4 +618,18 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<name>gozap构件发布版仓库</name>
|
||||
<url>http://repo.gozap.com/repos/content/repositories/gozap/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>snapshots</id>
|
||||
<name>gozap构件快照版仓库</name>
|
||||
<url>http://repo.gozap.com/repos/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -20,8 +20,10 @@ import static com.alibaba.druid.util.Utils.getBoolean;
|
||||
import java.io.Closeable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.Timestamp;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.ConcurrentModificationException;
|
||||
@@ -1013,6 +1015,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
if (isRemoveAbandoned()) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
poolableConnection.setConnectStackTrace(stackTrace);
|
||||
poolableConnection.setConnectedTime();
|
||||
poolableConnection.setConnectedTimeNano();
|
||||
poolableConnection.setTraceEnable(true);
|
||||
|
||||
@@ -1995,6 +1998,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
}
|
||||
|
||||
if (abandonedList.size() > 0) {
|
||||
SimpleDateFormat connectedTimeFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
for (DruidPooledConnection pooledConnection : abandonedList) {
|
||||
synchronized (pooledConnection) {
|
||||
if (pooledConnection.isDisable()) {
|
||||
@@ -2010,6 +2014,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
if (isLogAbandoned()) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("abandon connection, open stackTrace\n");
|
||||
buf.append("ownerThread " + pooledConnection.getOwnerThread() + " getConnect at " + connectedTimeFormate.format(new Date(pooledConnection.getConnectedTime())) + "\n");
|
||||
|
||||
StackTraceElement[] trace = pooledConnection.getConnectStackTrace();
|
||||
for (int i = 0; i < trace.length; i++) {
|
||||
@@ -2017,6 +2022,13 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
buf.append(trace[i].toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
buf.append("ownerThread current state is "+pooledConnection.getOwnerThread().getState() + ", current stackTrace\n");
|
||||
trace = pooledConnection.getOwnerThread().getStackTrace();
|
||||
for (int i = 0; i < trace.length; i++) {
|
||||
buf.append("\tat ");
|
||||
buf.append(trace[i].toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
LOG.error(buf.toString());
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
private boolean closed = false;
|
||||
private final Thread ownerThread;
|
||||
|
||||
private long connectedTime = 0;
|
||||
private long connectedTimeNano;
|
||||
private volatile boolean running = false;
|
||||
|
||||
@@ -84,6 +85,13 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
ownerThread = Thread.currentThread();
|
||||
}
|
||||
|
||||
public void setConnectedTime(){
|
||||
this.connectedTime = System.currentTimeMillis();
|
||||
}
|
||||
public long getConnectedTime() {
|
||||
return connectedTime;
|
||||
}
|
||||
|
||||
public Thread getOwnerThread() {
|
||||
return ownerThread;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import EDU.oswego.cs.dl.util.concurrent.CountDown;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MaxWaitTest extends TestCase {
|
||||
|
||||
Reference in New Issue
Block a user