01: /*
02: File: ThreadedExecutor.java
03:
04: Originally written by Doug Lea and released into the public domain.
05: This may be used for any purposes whatsoever without acknowledgment.
06: Thanks for the assistance and support of Sun Microsystems Labs,
07: and everyone contributing, testing, and using this code.
08:
09: History:
10: Date Who What
11: 21Jun1998 dl Create public version
12: 28aug1998 dl factored out ThreadFactoryUser
13: */
14:
15: package EDU.oswego.cs.dl.util.concurrent;
16:
17: /**
18: *
19: * An implementation of Executor that creates a new
20: * Thread that invokes the run method of the supplied command.
21: *
22: * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
23: **/
24: public class ThreadedExecutor extends ThreadFactoryUser implements
25: Executor {
26:
27: /**
28: * Execute the given command in a new thread.
29: **/
30: public synchronized void execute(Runnable command)
31: throws InterruptedException {
32: if (Thread.interrupted())
33: throw new InterruptedException();
34:
35: Thread thread = getThreadFactory().newThread(command);
36: thread.start();
37: }
38: }
|