01: package org.testng.internal.thread.port;
02:
03: import org.testng.TestNGException;
04: import org.testng.internal.thread.IPooledExecutor;
05:
06: import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
07: import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException;
08: import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
09: import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
10:
11: /**
12: * IPooledExecutor implementation based on ThreadPoolExecutor.
13: *
14: * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
15: */
16: public class PooledExecutorAdapter extends ThreadPoolExecutor implements
17: IPooledExecutor {
18: public PooledExecutorAdapter(int poolSize) {
19: super (poolSize, poolSize, 0L, TimeUnit.MILLISECONDS,
20: new LinkedBlockingQueue());
21: }
22:
23: public void execute(Runnable run) {
24: try {
25: super .execute(run);
26: } catch (RejectedExecutionException ree) {
27: throw new TestNGException(
28: "Task was not accepted for execution", ree);
29: }
30: }
31:
32: public void awaitTermination(long timeout)
33: throws InterruptedException {
34: super.awaitTermination(timeout, TimeUnit.MILLISECONDS);
35: }
36: }
|