01: package org.testng.internal.thread.port;
02:
03: import org.testng.internal.thread.IExecutor;
04: import org.testng.internal.thread.IFutureResult;
05: import org.testng.internal.thread.IThreadFactory;
06:
07: import edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue;
08: import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
09: import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
10:
11: /**
12: * ThreadPoolExecutor adaptor.
13: *
14: * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
15: */
16: public class ExecutorAdapter extends ThreadPoolExecutor implements
17: IExecutor {
18: public ExecutorAdapter(int threadCount, IThreadFactory tf) {
19: super (
20: threadCount,
21: threadCount,
22: 0L,
23: TimeUnit.MILLISECONDS,
24: new ArrayBlockingQueue(threadCount),
25: (edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory) tf
26: .getThreadFactory());
27: }
28:
29: public IFutureResult submitRunnable(final Runnable runnable) {
30: return new FutureResultAdapter(super .submit(runnable));
31: }
32:
33: public boolean awaitTermination(long timeout) {
34: boolean result = false;
35: try {
36: result = super .awaitTermination(timeout,
37: TimeUnit.MILLISECONDS);
38: } catch (InterruptedException iex) {
39: System.out
40: .println("[WARN] ThreadPoolExecutor has been interrupted while awaiting termination");
41: Thread.currentThread().interrupt();
42: }
43:
44: return result;
45: }
46:
47: public void stopNow() {
48: super.shutdownNow();
49: }
50:
51: }
|