1. /*
  2. * @(#)ThreadFactory.java 1.4 04/01/12
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.util.concurrent;
  8. /**
  9. * An object that creates new threads on demand. Using thread factories
  10. * removes hardwiring of calls to {@link Thread#Thread(Runnable) new Thread},
  11. * enabling applications to use special thread subclasses, priorities, etc.
  12. *
  13. * <p>
  14. * The simplest implementation of this interface is just:
  15. * <pre>
  16. * class SimpleThreadFactory implements ThreadFactory {
  17. * public Thread newThread(Runnable r) {
  18. * return new Thread(r);
  19. * }
  20. * }
  21. * </pre>
  22. *
  23. * The {@link Executors#defaultThreadFactory} method provides a more
  24. * useful simple implementation, that sets the created thread context
  25. * to known values before returning it.
  26. * @since 1.5
  27. * @author Doug Lea
  28. */
  29. public interface ThreadFactory {
  30. /**
  31. * Constructs a new <tt>Thread</tt>. Implementations may also initialize
  32. * priority, name, daemon status, <tt>ThreadGroup</tt>, etc.
  33. *
  34. * @param r a runnable to be executed by new thread instance
  35. * @return constructed thread
  36. */
  37. Thread newThread(Runnable r);
  38. }