Class ThreadCreator

java.lang.Object
com.iohao.net.common.kit.concurrent.ThreadCreator
Direct Known Subclasses:
DaemonThreadFactory, FixedNameThreadFactory

public class ThreadCreator extends Object
Base class for creating threads with configurable name prefix, priority, daemon flag, and thread group.
Author:
渔民小镇
date:
2023-04-02
  • Field Details

    • threadNamePrefix

      protected String threadNamePrefix
    • threadPriority

      protected int threadPriority
    • daemon

      protected boolean daemon
    • threadGroup

      protected ThreadGroup threadGroup
    • threadCount

      protected final AtomicInteger threadCount
  • Constructor Details

    • ThreadCreator

      public ThreadCreator(String threadNamePrefix)
  • Method Details

    • setThreadGroupName

      public void setThreadGroupName(String name)
      Set the thread group by name.
      Parameters:
      name - the thread group name
    • createThread

      public Thread createThread(Runnable runnable)
      Create a new thread with the configured group, name, priority, and daemon flag.
      Parameters:
      runnable - the task to execute
      Returns:
      the newly created thread
    • nextThreadName

      protected String nextThreadName()
      Generate the next thread name using the prefix and an auto-incrementing counter.
      Returns:
      the next thread name