Thread.sleep(100);
assertEquals(1, count.get());
}
@Test public void testPriorities() throws Exception {
final ThreadReuseExecutor pool = new ThreadReuseExecutor("test", 1); //$NON-NLS-1$
FutureWork<Boolean> work1 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
synchronized (pool) {
while (pool.getSubmittedCount() < 4) {
pool.wait();
}
}
return true;
}
}, 0);
final ConcurrentLinkedQueue<Integer> order = new ConcurrentLinkedQueue<Integer>();
FutureWork<Boolean> work2 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(2);
return true;
}
}, 2);
FutureWork<Boolean> work3 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(3);
return false;
}
}, 1);
Thread.sleep(20); //ensure a later timestamp
FutureWork<Boolean> work4 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(4);
return false;
}
}, 2);
pool.execute(work1);
pool.execute(work2);
pool.execute(work3);
pool.execute(work4);
synchronized (pool) {
pool.notifyAll();
}
work1.get();
work2.get();
work3.get();
work4.get();