content: package com.dahuaboke.redisx.common.thread;
  
  import io.netty.util.concurrent.FastThreadLocalThread;
  import io.netty.util.internal.ObjectUtil;
  
  import java.util.concurrent.ThreadFactory;
  import java.util.concurrent.atomic.AtomicInteger;
  
  /**
   * 2024/5/14 17:55
   * auth: dahua
   * desc: netty线程池重写了一下
   */
  public class RedisxThreadFactory implements ThreadFactory {
  
      private final AtomicInteger nextId = new AtomicInteger();
      private final String prefix;
      private final boolean daemon;
      private final int priority;
      protected final ThreadGroup threadGroup;
  
      public RedisxThreadFactory(String poolName) {
          this(poolName, false, Thread.NORM_PRIORITY, null);
      }
  
      public RedisxThreadFactory(String poolName, boolean daemon, int priority, ThreadGroup threadGroup) {
          ObjectUtil.checkNotNull(poolName, "poolName");
          if (priority < Thread.MIN_PRIORITY || priority > Thread.MAX_PRIORITY) {
              throw new IllegalArgumentException(
                      "priority: " + priority + " (expected: Thread.MIN_PRIORITY <= priority <= Thread.MAX_PRIORITY)");
          }
          prefix = poolName + '-';
          this.daemon = daemon;
          this.priority = priority;
          this.threadGroup = threadGroup;
      }
  
      public Thread newThread(Runnable r) {
          Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet());
          try {
              if (t.isDaemon() != daemon) {
                  t.setDaemon(daemon);
              }
  
              if (t.getPriority() != priority) {
                  t.setPriority(priority);
              }
          } catch (Exception ignored) {
              // Doesn't matter even if failed to set.
          }
          return t;
      }
  
      protected Thread newThread(Runnable r, String name) {
          return new FastThreadLocalThread(threadGroup, r, name);
      }
  }
  