Class ThreadPoolGovernor

java.lang.Object
com.alipay.sofa.common.thread.ThreadPoolGovernor

public class ThreadPoolGovernor extends Object
The governor to manager the ThreadPoolExecutors
Author:
Alaneuler Created on 2020/3/17
  • Field Details

    • CLASS_NAME

      public static String CLASS_NAME
  • Method Details

    • getInstance

      public static ThreadPoolGovernor getInstance()
    • startGovernorSchedule

      public void startGovernorSchedule()
      Start the governor info dump task
    • stopGovernorSchedule

      public void stopGovernorSchedule()
      Stop the governor info dump task
    • getGovernorPeriod

      public long getGovernorPeriod()
      The period of the dump task
      Returns:
      the period
    • setGovernorPeriod

      public void setGovernorPeriod(long governorPeriod)
      update the period of the dump task, then restart the task
      Parameters:
      governorPeriod - the dump task period
    • isGovernorLoggable

      public boolean isGovernorLoggable()
      The log switch of the dump task
      Returns:
      whether log the dump
    • setGovernorLoggable

      public void setGovernorLoggable(boolean governorLoggable)
      Update the log switch of the dump task
      Parameters:
      governorLoggable - whether log the dump
    • isGlobalMonitorLoggable

      public boolean isGlobalMonitorLoggable()
      The log switch of the all monitor task
      Returns:
      whether log monitor task
    • setGlobalMonitorLoggable

      public void setGlobalMonitorLoggable(boolean globalMonitorLoggable)
      Update the log switch of the all monitor task
      Parameters:
      globalMonitorLoggable - whether log monitor task
    • registerThreadPoolExecutor

      public void registerThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor, ThreadPoolConfig threadPoolConfig, ThreadPoolStatistics threadPoolStatistics)
      Register the ThreadPoolExecutor with ThreadPoolConfig and ThreadPoolStatistics to the governor
      Parameters:
      threadPoolExecutor - the base thread pool
      threadPoolConfig - the description of the thread pool
      threadPoolStatistics - the running statistics of the thread pool
    • unregisterThreadPoolExecutor

      public void unregisterThreadPoolExecutor(ThreadPoolConfig threadPoolConfig)
      Unregister the ThreadPoolExecutor by it's ThreadPoolConfig
      Parameters:
      threadPoolConfig - the description of the thread pool, it's identity is unique
    • getThreadPoolExecutor

      public ThreadPoolExecutor getThreadPoolExecutor(String identity)
      Get the ThreadPoolExecutor by it's identity
      Parameters:
      identity - the unique identity
      Returns:
      the ThreadPoolExecutor
    • getThreadPoolMonitorWrapper

      public ThreadPoolMonitorWrapper getThreadPoolMonitorWrapper(String identity)
      Get the ThreadPoolMonitorWrapper by it's identity
      Parameters:
      identity - the unique identity
      Returns:
      the ThreadPoolMonitorWrapper
    • startMonitorThreadPool

      public void startMonitorThreadPool(String identity)
      Start the monitor the ThreadPoolExecutor registered in the governor
      Parameters:
      identity - the unique identity
    • stopMonitorThreadPool

      public void stopMonitorThreadPool(String identity)
      Stop to monitor the ThreadPoolExecutor registered in the governor
      Parameters:
      identity - the unique identity
    • restartMonitorThreadPool

      public void restartMonitorThreadPool(String identity)
      Restart the monitor the ThreadPoolExecutor registered in the governor
      Parameters:
      identity - the unique identity
    • getMonitorScheduler

      public ScheduledExecutorService getMonitorScheduler()
      The thread pool to executor the monitor tasks
      Returns:
      the ScheduledExecutorService
    • getSpaceNameThreadPoolNumber

      public int getSpaceNameThreadPoolNumber(String spaceName)
      return the spaceName thread pool number,it will increase after witch get return 0 when the spaceName has not registered
      Parameters:
      spaceName - the spaceName
      Returns:
      the spaceName thread pool number
    • startMonitorThreadPoolBySpaceName

      public void startMonitorThreadPoolBySpaceName(String spaceName)
      start monitor all thread pool in the spaceName
      Parameters:
      spaceName - the spaceName
    • stopMonitorThreadPoolBySpaceName

      public void stopMonitorThreadPoolBySpaceName(String spaceName)
      stop monitor all thread pool in the spaceName
      Parameters:
      spaceName - the spaceName
    • setMonitorThreadPoolBySpaceName

      public void setMonitorThreadPoolBySpaceName(String spaceName, long period)
      update the monitor params and restart all thread pool in the spaceName
      Parameters:
      spaceName - the spaceName