01: /*
02: File: ThreadFactoryUser.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: 28aug1998 dl refactored from Executor classes
12: */
13:
14: package EDU.oswego.cs.dl.util.concurrent;
15:
16: /**
17: *
18: * Base class for Executors and related classes that rely on thread factories.
19: * Generally intended to be used as a mixin-style abstract class, but
20: * can also be used stand-alone.
21: * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
22: **/
23:
24: public class ThreadFactoryUser {
25:
26: protected ThreadFactory threadFactory_ = new DefaultThreadFactory();
27:
28: protected static class DefaultThreadFactory implements
29: ThreadFactory {
30: public Thread newThread(Runnable command) {
31: return new Thread(command);
32: }
33: }
34:
35: /**
36: * Set the factory for creating new threads.
37: * By default, new threads are created without any special priority,
38: * threadgroup, or status parameters.
39: * You can use a different factory
40: * to change the kind of Thread class used or its construction
41: * parameters.
42: * @param factory the factory to use
43: * @return the previous factory
44: **/
45:
46: public synchronized ThreadFactory setThreadFactory(
47: ThreadFactory factory) {
48: ThreadFactory old = threadFactory_;
49: threadFactory_ = factory;
50: return old;
51: }
52:
53: /**
54: * Get the factory for creating new threads.
55: **/
56: public synchronized ThreadFactory getThreadFactory() {
57: return threadFactory_;
58: }
59:
60: }
|