Package digilib.util

Class DigilibJobCenter<V>


  • public class DigilibJobCenter<V>
    extends Object
    Wrapper around ExecutionService.
    Author:
    casties
    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
        general logger for this class
    • Constructor Detail

      • DigilibJobCenter

        public DigilibJobCenter​(int maxThreads,
                                int maxQueueLen,
                                boolean prestart,
                                String label)
        Create a DigilibJobcenter with the given number of threads and queue length. If prestart=true it starts the threads in the thread pool.
        Parameters:
        maxThreads - the max threads
        maxQueueLen - the max queue length
        prestart - the prestart
        label - the label
    • Method Detail

      • submit

        public Future<V> submit​(Callable<V> job)
        Submit Callable job that returns a Value to execute.
        Parameters:
        job - the Callable
        Returns:
        Future to control the job
      • submit

        public Future<?> submit​(Runnable job)
        Submit Runnable job to execute.
        Parameters:
        job - the Runnable
        Returns:
        Future to control the job
      • isBusy

        public boolean isBusy()
        Returns if the service is overloaded.
        Returns:
        true if busy
      • getRunningJobs

        public int getRunningJobs()
        Returns the number of currently running jobs.
        Returns:
        the number of running jobs
      • getWaitingJobs

        public int getWaitingJobs()
        Returns the number of currently waiting jobs.
        Returns:
        the number of waiting jobs
      • setMaxThreads

        public void setMaxThreads​(int maxThreads)
        Parameters:
        maxThreads - the max threads
      • getMaxThreads

        public int getMaxThreads()
        Returns:
        the max threads
      • setMaxQueueLen

        public void setMaxQueueLen​(int maxQueueLen)
        Parameters:
        maxQueueLen - the max queue length
      • getMaxQueueLen

        public int getMaxQueueLen()
        Returns:
        the max queue length
      • shutdownNow

        public List<Runnable> shutdownNow()
        Shuts down the Executor. Tries to stop running threads and returns a list of waiting threads.
        Returns:
        list of waiting tasks