Most visited

Recently visited

Added in API level 1

ThreadFactory

public interface ThreadFactory

java.util.concurrent.ThreadFactory


按需创建新线程的对象。 使用线程工厂可以将调用的硬连线移除到new Thread ,从而使应用程序可以使用特殊的线程子类,优先级等。

这个接口的最简单的实现是:

 class SimpleThreadFactory implements ThreadFactory {
   public Thread newThread(Runnable r) {
     return new Thread(r);
   }
 }
The defaultThreadFactory() method provides a more useful simple implementation, that sets the created thread context to known values before returning it.

Summary

Public methods

abstract Thread newThread(Runnable r)

构造一个新的 Thread

Public methods

newThread

Added in API level 1
Thread newThread (Runnable r)

构造一个新的Thread 实现还可以初始化优先级,名称,守护进程状态, ThreadGroup等。

Parameters
r Runnable: a runnable to be executed by new thread instance
Returns
Thread constructed thread, or null if the request to create a thread is rejected

Hooray!