Fixed small bug in the benchmark test
This commit is contained in:
@@ -25,7 +25,7 @@ public class PoolBenchmark {
|
|||||||
// withoutPool();
|
// withoutPool();
|
||||||
withPool();
|
withPool();
|
||||||
long elapsed = System.currentTimeMillis() - t;
|
long elapsed = System.currentTimeMillis() - t;
|
||||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
System.out.println(((1000 * 3 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void withoutPool() throws InterruptedException {
|
private static void withoutPool() throws InterruptedException {
|
||||||
@@ -66,30 +66,31 @@ public class PoolBenchmark {
|
|||||||
pool.init();
|
pool.init();
|
||||||
List<Thread> tds = new ArrayList<Thread>();
|
List<Thread> tds = new ArrayList<Thread>();
|
||||||
|
|
||||||
final AtomicInteger ind = new AtomicInteger();
|
final AtomicInteger ind = new AtomicInteger();
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
Thread hj = new Thread(new Runnable() {
|
Thread hj = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
for(int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS; ) {
|
for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) {
|
||||||
try {
|
try {
|
||||||
Jedis j = pool.getResource();
|
Jedis j = pool.getResource();
|
||||||
final String key = "foo" + i;
|
j.auth("foobared");
|
||||||
j.set(key, key);
|
final String key = "foo" + i;
|
||||||
j.get(key);
|
j.set(key, key);
|
||||||
pool.returnResource(j);
|
j.get(key);
|
||||||
} catch (Exception e) {
|
pool.returnResource(j);
|
||||||
e.printStackTrace();
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tds.add(hj);
|
tds.add(hj);
|
||||||
hj.start();
|
hj.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Thread t : tds)
|
for (Thread t : tds)
|
||||||
t.join();
|
t.join();
|
||||||
|
|
||||||
pool.destroy();
|
pool.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user