1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-26 01:38:57 -05:00
filebot/source/net/sourceforge/tuned/DefaultThreadFactory.java
Reinhard Pointner ca032f3b56 + Script expressions in ExpressionFormat will now be evaluated in a secure sandbox
+ "preserve Extension" can be enabled/disabled in RenameModel

* fixed rename list SelectionModel performance issue 
* create package for ui-independant Hash* stuff
2009-05-02 23:34:04 +00:00

57 lines
1.3 KiB
Java

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;
public DefaultThreadFactory(String name) {
this(name, Thread.NORM_PRIORITY);
}
public DefaultThreadFactory(String name, int priority) {
this(name, priority, false);
}
public DefaultThreadFactory(String groupName, int priority, boolean daemon) {
SecurityManager sm = System.getSecurityManager();
ThreadGroup parentGroup = (sm != null) ? sm.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.group = new ThreadGroup(parentGroup, groupName);
this.daemon = daemon;
this.priority = priority;
}
public Thread newThread(Runnable r) {
Thread thread = new Thread(group, r, String.format("%s-thread-%d", group.getName(), threadNumber.incrementAndGet()));
if (daemon != thread.isDaemon())
thread.setDaemon(daemon);
if (priority != thread.getPriority())
thread.setPriority(priority);
return thread;
}
public ThreadGroup getThreadGroup() {
return group;
}
}