01: package dalma.helpers;
02:
03: import dalma.Executor;
04:
05: import java.util.concurrent.ExecutorService;
06: import java.util.concurrent.TimeUnit;
07:
08: /**
09: * {@link Executor} that simply delegates to JDK 5.0's
10: * {@link java.util.concurrent.Executor}.
11: *
12: * @author Kohsuke Kawaguchi
13: */
14: public class Java5Executor implements Executor {
15: private final ExecutorService core;
16:
17: public Java5Executor(ExecutorService core) {
18: this .core = core;
19: }
20:
21: public void execute(Runnable command) {
22: core.execute(command);
23: }
24:
25: public void stop(long timeout) throws InterruptedException {
26: core.shutdown();
27: if (timeout == 0) {
28: while (!core.isTerminated())
29: core.awaitTermination(1000, TimeUnit.SECONDS);
30: } else
31: core.awaitTermination(timeout, TimeUnit.MILLISECONDS);
32: }
33: }
|