Class CmsSchedulerThreadPool

  • All Implemented Interfaces:
    org.quartz.spi.ThreadPool

    public class CmsSchedulerThreadPool
    extends java.lang.Object
    implements org.quartz.spi.ThreadPool
    Simple thread pool used for the Quartz scheduler in OpenCms.

    Since:
    6.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsSchedulerThreadPool()
      Create a new CmsSchedulerThreadPool with default values.
      CmsSchedulerThreadPool​(int initialThreadCount, int maxThreadCount, int threadPriority)
      Create a new CmsSchedulerThreadPool with the specified number of threads that have the given priority.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int blockForAvailableThreads()  
      protected java.lang.Runnable getNextRunnable()
      Dequeue the next pending Runnable.
      int getPoolSize()  
      int getThreadPriority()
      Returns the thread priority of the threads in the scheduler pool.
      void initialize()  
      boolean runInThread​(java.lang.Runnable runnable)
      Run the given Runnable object in the next available Thread.
      void setInstanceId​(java.lang.String schedInstId)  
      void setInstanceName​(java.lang.String schedName)  
      void shutdown()
      Terminate any worker threads in this thread group.
      void shutdown​(boolean waitForJobsToComplete)
      Terminate all threads in this thread group.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CmsSchedulerThreadPool

        public CmsSchedulerThreadPool​(int initialThreadCount,
                                      int maxThreadCount,
                                      int threadPriority)
        Create a new CmsSchedulerThreadPool with the specified number of threads that have the given priority. The OpenCms scheduler thread pool will initially start with provided number of active scheduler threads. When a thread is requested by the scheduler, and no "free" threads are available, a new thread will be added to the pool and used for execution. The pool will be allowed to grow until it has reached the configured number of maximum threads.

        Parameters:
        initialThreadCount - the initial number of threads for the pool
        maxThreadCount - maximum number of threads the pool is allowed to grow
        threadPriority - the thread priority for the scheduler threads
        See Also:
        Thread
    • Method Detail

      • blockForAvailableThreads

        public int blockForAvailableThreads()
        Specified by:
        blockForAvailableThreads in interface org.quartz.spi.ThreadPool
        Returns:
        if the pool should be blocked for available threads
        See Also:
        ThreadPool
      • getPoolSize

        public int getPoolSize()
        Specified by:
        getPoolSize in interface org.quartz.spi.ThreadPool
        See Also:
        ThreadPool.getPoolSize()
      • getThreadPriority

        public int getThreadPriority()
        Returns the thread priority of the threads in the scheduler pool.

        Returns:
        the thread priority of the threads in the scheduler pool
      • initialize

        public void initialize()
                        throws org.quartz.SchedulerConfigException
        Specified by:
        initialize in interface org.quartz.spi.ThreadPool
        Throws:
        org.quartz.SchedulerConfigException
        See Also:
        ThreadPool.initialize()
      • runInThread

        public boolean runInThread​(java.lang.Runnable runnable)
        Run the given Runnable object in the next available Thread.

        If while waiting the thread pool is asked to shut down, the Runnable is executed immediately within a new additional thread.

        Specified by:
        runInThread in interface org.quartz.spi.ThreadPool
        Parameters:
        runnable - the Runnable to run
        Returns:
        true if the Runnable was run
      • shutdown

        public void shutdown()
        Terminate any worker threads in this thread group.

        Jobs currently in progress will be allowed to complete.

      • shutdown

        public void shutdown​(boolean waitForJobsToComplete)
        Terminate all threads in this thread group.

        Specified by:
        shutdown in interface org.quartz.spi.ThreadPool
        Parameters:
        waitForJobsToComplete - if true,, all current jobs will be allowed to complete
      • getNextRunnable

        protected java.lang.Runnable getNextRunnable()
                                              throws java.lang.InterruptedException
        Dequeue the next pending Runnable.

        Returns:
        the next pending Runnable
        Throws:
        java.lang.InterruptedException - if something goes wrong
      • setInstanceId

        public void setInstanceId​(java.lang.String schedInstId)
        Specified by:
        setInstanceId in interface org.quartz.spi.ThreadPool
      • setInstanceName

        public void setInstanceName​(java.lang.String schedName)
        Specified by:
        setInstanceName in interface org.quartz.spi.ThreadPool