Class WorkerPool


  • public class WorkerPool
    extends java.lang.Object
    A simple static workpool. Worker threads are created when necessary.
    Author:
    Thomas Morgner
    • Constructor Summary

      Constructors 
      Constructor Description
      WorkerPool()
      Creates a new worker pool with the default size of 10 workers and the default name.
      WorkerPool​(int size)
      Creates a new workerpool with the given number of workers and the default name.
      WorkerPool​(int size, java.lang.String namePrefix)
      Creates a new worker pool for the given number of workers and with the given name prefix.
    • Constructor Detail

      • WorkerPool

        public WorkerPool()
        Creates a new worker pool with the default size of 10 workers and the default name.
      • WorkerPool

        public WorkerPool​(int size)
        Creates a new workerpool with the given number of workers and the default name.
        Parameters:
        size - the maximum number of workers available.
      • WorkerPool

        public WorkerPool​(int size,
                          java.lang.String namePrefix)
        Creates a new worker pool for the given number of workers and with the given name prefix.
        Parameters:
        size - the size of the worker pool.
        namePrefix - the name prefix for all created workers.
    • Method Detail

      • isWorkerAvailable

        public boolean isWorkerAvailable()
        Checks, whether workers are available.
        Returns:
        true, if at least one worker is idle, false otherwise.
      • getWorkerForWorkload

        public WorkerHandle getWorkerForWorkload​(java.lang.Runnable r)
        Returns a workerhandle for the given workload. This method will wait until an idle worker is found.
        Parameters:
        r - the workload for the worker
        Returns:
        a handle to the worker.
      • workerFinished

        public void workerFinished​(Worker worker)
        Marks the given worker as finished. The worker will be removed from the list of the available workers.
        Parameters:
        worker - the worker which was finished.
      • workerAvailable

        public void workerAvailable​(Worker worker)
        Marks the given worker as available.
        Parameters:
        worker - the worker which was available.
      • finishAll

        public void finishAll()
        Finishes all worker of this pool.