JMX增强

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@688 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-08 01:59:29 +00:00
parent f52a0efe57
commit 7f9a640a71
3 changed files with 23 additions and 9 deletions
@@ -76,6 +76,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private long destroyCount = 0L;
private long removeAbandonedCount = 0L;
private long notEmptyWaitCount = 0L;
private long notEmptySignalCount = 0L;
private long notEmptyWaitNanos = 0L;
// store
@@ -121,6 +122,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
this.enable = enable;
if (!enable) {
notEmpty.signalAll();
notEmptySignalCount++;
}
} finally {
lock.unlock();
@@ -528,6 +530,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
enable = false;
notEmpty.signalAll();
notEmptySignalCount++;
} finally {
lock.unlock();
}
@@ -547,6 +550,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
connections[poolingCount++] = e;
notEmpty.signal();
notEmptySignalCount++;
}
ConnectionHolder takeLast() throws InterruptedException, SQLException {
@@ -563,6 +567,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
} catch (InterruptedException ie) {
notEmpty.signal(); // propagate to non-interrupted thread
notEmptySignalCount++;
throw ie;
}
@@ -596,6 +601,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
} catch (InterruptedException ie) {
notEmpty.signal(); // propagate to non-interrupted thread
notEmptySignalCount++;
throw ie;
}
@@ -677,17 +683,18 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
try {
// 防止创建超过maxActive数量的连接
if (activeCount + poolingCount >= maxActive) {
empty.await();
continue;
}
// 必须存在线程等待,才创建连接
int waitThreadCount = lock.getWaitQueueLength(notEmpty);
if (poolingCount >= waitThreadCount) {
notEmpty.signal(); // 防止信号丢失引起的等待
notEmptySignalCount++;
empty.await();
continue;
}
// 防止创建超过maxActive数量的连接
if (activeCount + poolingCount >= maxActive) {
empty.await();
continue;
}
@@ -742,6 +749,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
errorCount = 0; // reset errorCount
notEmpty.signal();
notEmptySignalCount++;
} finally {
lock.unlock();
}
@@ -951,6 +959,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return notEmptyWaitCount;
}
public long getNotEmptySignalCount() {
return notEmptySignalCount;
}
public long getNotEmptyWaitMillis() {
return notEmptyWaitNanos / (1000 * 1000);
}
@@ -31,6 +31,8 @@ public interface DruidDataSourceMBean extends DruidAbstractDataSourceMBean {
int getLockQueueLength();
long getNotEmptyWaitCount();
long getNotEmptySignalCount();
long getNotEmptyWaitMillis();
@@ -47,7 +47,7 @@ public class Case1 extends TestCase {
private String validationQuery = "SELECT 1";
private int threadCount = 40;
private int loopCount = 4;
final int LOOP_COUNT = 1000 * 10;
final int LOOP_COUNT = 1000 * 100;
protected void setUp() throws Exception {
jdbcUrl = "jdbc:fake:dragoon_v25masterdb";
@@ -78,7 +78,7 @@ public class Case1 extends TestCase {
System.out.println();
}
public void ftest_1() throws Exception {
public void f_test_1() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setInitialSize(initialSize);
@@ -100,7 +100,7 @@ public class Case1 extends TestCase {
System.out.println();
}
public void test_2() throws Exception {
public void f_test_2() throws Exception {
BoneCPDataSource dataSource = new BoneCPDataSource();
// dataSource.(10);
// dataSource.setMaxActive(50);