|
|
< Day Day Up > |
|
10.5 Thread CreationThe thread pool dynamically creates threads according to the size policies in effect when a task is queued and terminates threads when they've been idle too long. Those policies are set when the pool is constructed, and they can be altered with these methods: package java.util.concurrent;
public interface ThreadFactory {
public Thread newThread(Runnable r);
}
package java.util.concurrent;
public class ThreadPoolExecutor implements ExecutorService {
public void setThreadFactory(ThreadFactory threadFactory);
public ThreadFactory getThreadFactory( );
public void setKeepAliveTime(long time, TimeUnit unit);
public long getKeepAliveTime(TimeUnit unit);
}When the pool creates a thread, it uses the currently installed thread pool factory to do so. Creating and installing your own thread factory allows you to set up a custom scheme to create threads so that they are created with special names, priorities, daemon status, thread group, and so on. The default thread factory creates a thread with the following characteristics:
|
|
|
< Day Day Up > |
|