Created
December 4, 2012 10:36
-
-
Save hujj0615/4202518 to your computer and use it in GitHub Desktop.
make threads have same name prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskThreadFactory implements ThreadFactory { | |
final ThreadGroup group; | |
final AtomicInteger threadNumber = new AtomicInteger(1); | |
final String namePrefix; | |
TaskThreadFactory(String namePrefix) { | |
SecurityManager s = System.getSecurityManager(); | |
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); | |
this.namePrefix = namePrefix; | |
} | |
public Thread newThread(Runnable r) { | |
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement()); | |
t.setDaemon(daemon); | |
t.setPriority(getThreadPriority()); | |
return t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment