mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
自己维护notEmptyWaitThreadCount计数
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@713 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.alibaba.druid.benckmark;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestAtomicPerformance extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
perf(count);
|
||||
}
|
||||
System.out.println();
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
perf2(count);
|
||||
}
|
||||
}
|
||||
|
||||
private void perf(AtomicInteger count) {
|
||||
long startMillis = System.currentTimeMillis();
|
||||
|
||||
count.set(0);
|
||||
for (int i = 0; i < 1000 * 1000 * 100; ++i) {
|
||||
int value = count.get();
|
||||
count.compareAndSet(value, value + 1);
|
||||
}
|
||||
|
||||
long millis = System.currentTimeMillis() - startMillis;
|
||||
System.out.println("millis " + millis);
|
||||
}
|
||||
|
||||
private void perf2(AtomicInteger count) {
|
||||
long startMillis = System.currentTimeMillis();
|
||||
|
||||
count.set(0);
|
||||
for (int i = 0; i < 1000 * 1000 * 100; ++i) {
|
||||
int value = count.get();
|
||||
count.weakCompareAndSet(value, value + 1);
|
||||
}
|
||||
|
||||
long millis = System.currentTimeMillis() - startMillis;
|
||||
System.out.println("weak millis " + millis);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class TestIdle3_Concurrent_Starvation extends TestCase {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
final int threadCount = 5;
|
||||
final int threadCount = 10;
|
||||
concurrent(threadCount);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user