You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Java 线程池最佳实践里面自己实现 ThreadFactory是不是有点问题? 文件:docs/java/concurrent/java-thread-pool-best-practices.md
#2241
Java 线程池最佳实践里面自己实现 ThreadFactory是不是有点问题? 文件:docs/java/concurrent/java-thread-pool-best-practices.md
mozou
opened this issue
Jan 11, 2024
· 1 comment
感谢指出,这样也可以:
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
* 线程工厂,它设置线程名称,有利于我们定位问题。
public final class NamingThreadFactory implements ThreadFactory {
private final AtomicInteger threadNum = new AtomicInteger();
private final String name;
* 创建一个带名字的线程池生产工厂
public NamingThreadFactory(String name) {
this.name = name;
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName(name + " [#" + threadNum.incrementAndGet() + "]");
return t;