java 风暴:nettyrenamethreadfactory为什么storm需要重命名线程名称

pdtvr36n  于 2021-06-21  发布在  Storm
关注(0)|答案(0)|浏览(179)

我正在浏览storm的源代码,特别是消息传递模块,我来看看 NettyRenameThreadFactory . 我不太明白为什么storm需要重命名线程名,这样做的根本原因是什么?在这里上课,我也不太明白的用法 ThreadNameDeterminer.CURRENT .

public class NettyRenameThreadFactory  implements ThreadFactory {

  static {
  //Rename Netty threads
   ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
  }

  final ThreadGroup group;
  final AtomicInteger index = new AtomicInteger(1);
  final String name;

  NettyRenameThreadFactory(String name) {
    SecurityManager s = System.getSecurityManager();
    group = (s != null)? s.getThreadGroup() :
                         Thread.currentThread().getThreadGroup();
    this.name = name;
  }

  public Thread newThread(Runnable r) {
    Thread t = new Thread(group, r, name + "-" + index.getAndIncrement(), 0);
    if (t.isDaemon())
        t.setDaemon(false);
    if (t.getPriority() != Thread.NORM_PRIORITY)
        t.setPriority(Thread.NORM_PRIORITY);
    return t;
  }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题