Skip to content

Instantly share code, notes, and snippets.

@miere
Created June 19, 2015 20:05
Show Gist options
  • Select an option

  • Save miere/c1f2c8f4b7de6939a703 to your computer and use it in GitHub Desktop.

Select an option

Save miere/c1f2c8f4b7de6939a703 to your computer and use it in GitHub Desktop.
@RequiredArgsConstructor
final public class NamedThreadFactory implements ThreadFactory {
private final AtomicInteger counter = new AtomicInteger(1);
final private String baseName;
@Override
public Thread newThread(final Runnable r) {
final Thread thread = new Thread(r, getNextMethod());
thread.setDaemon(true);
if (thread.getPriority() != Thread.NORM_PRIORITY)
thread.setPriority(Thread.NORM_PRIORITY);
return thread;
}
private String getNextMethod() {
return baseName + "-" + counter.getAndIncrement();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment