2008-03-26 20:28:06 -04:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
|
|
|
public class DefaultThreadFactory implements ThreadFactory {
|
|
|
|
|
|
|
|
private final AtomicInteger threadNumber = new AtomicInteger(0);
|
|
|
|
private final ThreadGroup group;
|
|
|
|
|
|
|
|
private final int priority;
|
|
|
|
private final boolean daemon;
|
|
|
|
|
|
|
|
|
2008-07-05 07:37:03 -04:00
|
|
|
public DefaultThreadFactory(String name) {
|
|
|
|
this(name, Thread.NORM_PRIORITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-26 20:28:06 -04:00
|
|
|
public DefaultThreadFactory(String name, int priority) {
|
|
|
|
this(name, priority, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DefaultThreadFactory(String groupName, int priority, boolean daemon) {
|
|
|
|
group = new ThreadGroup(groupName);
|
|
|
|
|
|
|
|
this.daemon = daemon;
|
|
|
|
this.priority = priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Thread newThread(Runnable r) {
|
2008-03-27 17:44:48 -04:00
|
|
|
Thread thread = new Thread(group, r, String.format("%s-thread-%d", group.getName(), threadNumber.incrementAndGet()));
|
2008-03-26 20:28:06 -04:00
|
|
|
|
2008-03-27 17:44:48 -04:00
|
|
|
thread.setDaemon(daemon);
|
|
|
|
thread.setPriority(priority);
|
2008-03-26 20:28:06 -04:00
|
|
|
|
2008-03-27 17:44:48 -04:00
|
|
|
return thread;
|
2008-03-26 20:28:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|