Class QueuedThreadPool

    • Constructor Detail

      • QueuedThreadPool

        public QueuedThreadPool()
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                @Name("threadGroup")
                                java.lang.ThreadGroup threadGroup)
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("reservedThreads")
                                int reservedThreads,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                @Name("threadGroup")
                                java.lang.ThreadGroup threadGroup)
    • Method Detail

      • setThreadPoolBudget

        public void setThreadPoolBudget​(ThreadPoolBudget budget)
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Starts the managed lifecycle beans in the order they were added.
        Overrides:
        doStart in class ContainerLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Stops the managed lifecycle beans in the reverse order they were added.
        Overrides:
        doStop in class ContainerLifeCycle
        Throws:
        java.lang.Exception
      • setDaemon

        public void setDaemon​(boolean daemon)
        Thread Pool should use Daemon Threading.
        Parameters:
        daemon - true to enable delegation
        See Also:
        Thread.setDaemon(boolean)
      • setIdleTimeout

        public void setIdleTimeout​(int idleTimeout)
        Set the maximum thread idle time. Threads that are idle for longer than this period may be stopped.
        Parameters:
        idleTimeout - Max idle time in ms.
        See Also:
        getIdleTimeout()
      • setReservedThreads

        public void setReservedThreads​(int reservedThreads)
        Set the number of reserved threads.
        Parameters:
        reservedThreads - number of reserved threads or -1 for heuristically determined
        See Also:
        getReservedThreads()
      • setName

        public void setName​(java.lang.String name)
        Parameters:
        name - Name of this thread pool to use when naming threads.
      • setThreadsPriority

        public void setThreadsPriority​(int priority)
        Set the priority of the pool threads.
        Parameters:
        priority - the new thread priority.
      • getIdleTimeout

        @ManagedAttribute("maximum time a thread may be idle in ms")
        public int getIdleTimeout()
        Get the maximum thread idle time.
        Returns:
        Max idle time in ms.
        See Also:
        setIdleTimeout(int)
      • getReservedThreads

        @ManagedAttribute("the number of reserved threads in the pool")
        public int getReservedThreads()
        Get the number of reserved threads.
        Returns:
        number of reserved threads or or -1 for heuristically determined
        See Also:
        setReservedThreads(int)
      • getName

        @ManagedAttribute("name of the thread pool")
        public java.lang.String getName()
        Returns:
        The name of the this thread pool
      • getThreadsPriority

        @ManagedAttribute("priority of threads in the pool")
        public int getThreadsPriority()
        Get the priority of the pool threads.
        Returns:
        the priority of the pool threads.
      • getQueueSize

        @ManagedAttribute("size of the job queue")
        public int getQueueSize()
        Get the size of the job queue.
        Returns:
        Number of jobs queued waiting for a thread
      • isDaemon

        @ManagedAttribute("thread pool uses daemon threads")
        public boolean isDaemon()
        Returns:
        whether this thread pool is using daemon threads
        See Also:
        Thread.setDaemon(boolean)
      • isDetailedDump

        @ManagedAttribute("reports additional details in the dump")
        public boolean isDetailedDump()
      • setDetailedDump

        public void setDetailedDump​(boolean detailedDump)
      • getLowThreadsThreshold

        @ManagedAttribute("threshold at which the pool is low on threads")
        public int getLowThreadsThreshold()
      • setLowThreadsThreshold

        public void setLowThreadsThreshold​(int lowThreadsThreshold)
      • execute

        public void execute​(java.lang.Runnable job)
        Specified by:
        execute in interface java.util.concurrent.Executor
        Specified by:
        execute in interface TryExecutor
      • tryExecute

        public boolean tryExecute​(java.lang.Runnable task)
        Description copied from interface: TryExecutor
        Attempt to execute a task.
        Specified by:
        tryExecute in interface TryExecutor
        Parameters:
        task - The task to be executed
        Returns:
        True IFF the task has been given directly to a thread to execute. The task cannot be queued pending the later availability of a Thread.
      • join

        public void join()
                  throws java.lang.InterruptedException
        Blocks until the thread pool is stopped.
        Specified by:
        join in interface ThreadPool
        Throws:
        java.lang.InterruptedException - if thread was interrupted
      • getThreads

        @ManagedAttribute("number of threads in the pool")
        public int getThreads()
        Specified by:
        getThreads in interface ThreadPool
        Returns:
        the total number of threads currently in the pool
      • getIdleThreads

        @ManagedAttribute("number of idle threads in the pool")
        public int getIdleThreads()
        Specified by:
        getIdleThreads in interface ThreadPool
        Returns:
        the number of idle threads in the pool
      • getBusyThreads

        @ManagedAttribute("number of busy threads in the pool")
        public int getBusyThreads()
        Returns:
        the number of busy threads in the pool
      • isLowOnThreads

        @ManagedAttribute(value="thread pool is low on threads",
                          readonly=true)
        public boolean isLowOnThreads()

        Returns whether this thread pool is low on threads.

        The current formula is:

         maxThreads - threads + idleThreads - queueSize <= lowThreadsThreshold
         
        Specified by:
        isLowOnThreads in interface ThreadPool
        Returns:
        whether the pool is low on threads
        See Also:
        getLowThreadsThreshold()
      • startThread

        protected void startThread()
      • newThread

        protected java.lang.Thread newThread​(java.lang.Runnable runnable)
      • removeThread

        protected void removeThread​(java.lang.Thread thread)
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Overrides:
        dump in class ContainerLifeCycle
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • runJob

        protected void runJob​(java.lang.Runnable job)

        Runs the given job in the current thread.

        Subclasses may override to perform pre/post actions before/after the job is run.

        Parameters:
        job - the job to run
      • getQueue

        protected java.util.concurrent.BlockingQueue<java.lang.Runnable> getQueue()
        Returns:
        the job queue
      • setQueue

        @Deprecated
        public void setQueue​(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
        Deprecated.
        pass the queue to the constructor instead
        Parameters:
        queue - the job queue
      • interruptThread

        @ManagedOperation("interrupts a pool thread")
        public boolean interruptThread​(@Name("id")
                                       long id)
        Parameters:
        id - the thread ID to interrupt.
        Returns:
        true if the thread was found and interrupted.
      • dumpThread

        @ManagedOperation("dumps a pool thread stack")
        public java.lang.String dumpThread​(@Name("id")
                                           long id)
        Parameters:
        id - the thread ID to interrupt.
        Returns:
        the stack frames dump