6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import java.util.concurrent.*; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
– |
import java.util.concurrent.locks.*; |
10 |
|
|
11 |
< |
import junit.framework.*; |
12 |
< |
import java.util.*; |
11 |
> |
import java.util.ArrayList; |
12 |
> |
import java.util.List; |
13 |
> |
import java.util.concurrent.ArrayBlockingQueue; |
14 |
> |
import java.util.concurrent.BlockingQueue; |
15 |
> |
import java.util.concurrent.Callable; |
16 |
> |
import java.util.concurrent.CountDownLatch; |
17 |
> |
import java.util.concurrent.ExecutionException; |
18 |
> |
import java.util.concurrent.Executors; |
19 |
> |
import java.util.concurrent.ExecutorService; |
20 |
> |
import java.util.concurrent.Future; |
21 |
> |
import java.util.concurrent.FutureTask; |
22 |
> |
import java.util.concurrent.LinkedBlockingQueue; |
23 |
> |
import java.util.concurrent.RejectedExecutionException; |
24 |
> |
import java.util.concurrent.RejectedExecutionHandler; |
25 |
> |
import java.util.concurrent.RunnableFuture; |
26 |
> |
import java.util.concurrent.SynchronousQueue; |
27 |
> |
import java.util.concurrent.ThreadFactory; |
28 |
> |
import java.util.concurrent.ThreadPoolExecutor; |
29 |
> |
import java.util.concurrent.TimeoutException; |
30 |
> |
import java.util.concurrent.TimeUnit; |
31 |
> |
import java.util.concurrent.locks.Condition; |
32 |
> |
import java.util.concurrent.locks.ReentrantLock; |
33 |
> |
|
34 |
> |
import junit.framework.Test; |
35 |
> |
import junit.framework.TestSuite; |
36 |
|
|
37 |
|
public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { |
38 |
|
public static void main(String[] args) { |
39 |
< |
junit.textui.TestRunner.run(suite()); |
39 |
> |
main(suite(), args); |
40 |
|
} |
41 |
|
public static Test suite() { |
42 |
|
return new TestSuite(ThreadPoolExecutorSubclassTest.class); |
58 |
|
CustomTask(final Runnable r, final V res) { |
59 |
|
if (r == null) throw new NullPointerException(); |
60 |
|
callable = new Callable<V>() { |
61 |
< |
public V call() throws Exception { r.run(); return res; }}; |
61 |
> |
public V call() throws Exception { r.run(); return res; }}; |
62 |
|
} |
63 |
|
public boolean isDone() { |
64 |
|
lock.lock(); try { return done; } finally { lock.unlock() ; } |
1269 |
|
CustomTPE p = new CustomTPE(); |
1270 |
|
try { |
1271 |
|
final CountDownLatch done = new CountDownLatch(1); |
1272 |
< |
final CheckedRunnable task = new CheckedRunnable() { |
1272 |
> |
p.execute(new CheckedRunnable() { |
1273 |
|
public void realRun() { |
1274 |
|
done.countDown(); |
1275 |
< |
}}; |
1255 |
< |
p.execute(task); |
1275 |
> |
}}); |
1276 |
|
await(p.afterCalled); |
1277 |
|
assertEquals(0, done.getCount()); |
1278 |
|
assertTrue(p.afterCalled()); |