Class JobQueue


  • public class JobQueue
    extends java.lang.Object
    Queue of Job instances.
    Author:
    Daniel Sagenschneider
    • Constructor Summary

      Constructors 
      Constructor Description
      JobQueue()
      Initiate with private lock.
      JobQueue​(java.lang.Object lock)
      Initiate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Job dequeue()
      Thread-safe dequeuing the next Job to execute.
      Job dequeue​(long timeout)
      Thread-safe dequeuing the next Job to execute.
      void enqueue​(Job job)
      Thread-safe enqueues a Job to the queue.
      boolean isEmpty()
      Indicates if no Job instances within the queue.
      void waitForTask​(long timeout)
      Waits the input period of time for another Job to be added.
      void wakeUp()
      Wakes up waiting on a Job.
      • Methods inherited from class java.lang.Object

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

      • JobQueue

        public JobQueue()
        Initiate with private lock.
      • JobQueue

        public JobQueue​(java.lang.Object lock)
        Initiate.
        Parameters:
        lock - Lock for coordinating this JobQueue.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Indicates if no Job instances within the queue.
        Returns:
        No Job instances within the queue.
      • enqueue

        public void enqueue​(Job job)
        Thread-safe enqueues a Job to the queue.
        Parameters:
        job - Job to add to the queue.
      • dequeue

        public Job dequeue()
        Thread-safe dequeuing the next Job to execute.
        Returns:
        Next Job to execute or null if no Job currently available.
      • dequeue

        public Job dequeue​(long timeout)
        Thread-safe dequeuing the next Job to execute. This will block for timeout milliseconds for a Job to become available.
        Parameters:
        timeout - Timeout to wait for dequeuing a Job.
        Returns:
        Next Job to execute or null if timed out waiting for next Job.
      • wakeUp

        public void wakeUp()
        Wakes up waiting on a Job.
      • waitForTask

        public void waitForTask​(long timeout)
        Waits the input period of time for another Job to be added.
        Parameters:
        timeout - Time to wait in milliseconds.