Created
May 13, 2016 21:59
-
-
Save nikkatsa/6ea7baa487fd73f3e9eb4c65d4567bad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class NamedThreadFactory implements ThreadFactory { | |
private final String name; | |
private final boolean isDaemon; | |
private final AtomicInteger threadCounter; | |
public NamedThreadFactory() { | |
this("Thread"); | |
} | |
public NamedThreadFactory(String name) { | |
this(name, true); | |
} | |
public NamedThreadFactory(String name, boolean isDaemon) { | |
this.name = name; | |
this.isDaemon = isDaemon; | |
this.threadCounter = new AtomicInteger(1); | |
} | |
@Override | |
public Thread newThread(final Runnable r) { | |
final Thread t = new Thread(); | |
t.setName(String.format("%s-%d", this.name, threadCounter.getAndIncrement())); | |
t.setDaemon(this.isDaemon); | |
return t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment