io.github.linmoure.thread.factory.NamedThreadFactory Maven / Gradle / Ivy
package io.github.linmoure.thread.factory;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
public class NamedThreadFactory implements ThreadFactory {
private static final AtomicInteger TAG = new AtomicInteger(0);
private final String name;
public NamedThreadFactory(String name) {
this.name = name;
}
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName(this.name + ":" + TAG.getAndIncrement());
return thread;
}
}