Documentation of 'jsat.utils.PoisonRunnable' Java class
PoisonRunnable
jsat.utils

Class PoisonRunnable

  • All Implemented Interfaces:
    java.lang.Runnable


    public final class PoisonRunnable
    extends java.lang.Object
    implements java.lang.Runnable
    A helper class for using the reader / writer model to implement parallel algorithms. When using the a BlockingQueue, null is an invalid value. However, if several threads have been started that are simply reading from the queue for jobs, we want to let the threads know when to stop. Polling can not be used since the BlockingQueue.take() operations blocks until a value is added. If the queue is a queue of Runnable jobs, this class solves the problem. An instanceof check can be done on the returned runnable. If it is a poisoned one, the worker knows to stop consuming and terminate.

    By default, the run() method does not perform any action. The poison runnable can be used to perform ending clean up work, such as posting to a semaphore, by giving the work job to the PoisonRunnable(java.lang.Runnable) constructor. The runnable given will be run when the Poison runnable's run method is called.
    • Constructor Summary

      Constructors 
      Constructor and Description
      PoisonRunnable()
      Creates a new PoisonRunnable that will do nothing when its run method is called.
      PoisonRunnable(java.util.concurrent.CountDownLatch latch)
      Creates a new PoisonRunnable that will call the CountDownLatch.countDown() method on the given latch when its run method is finally called.
      PoisonRunnable(java.util.concurrent.CyclicBarrier barrier)
      Creates a new PoisonRunnable that will call the CyclicBarrier.await() method of the given barrier when its run method is finally called.
      PoisonRunnable(java.lang.Runnable lastStep)
      Creates a new PoisonRunnable that will run the given runnable when it is called.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void run() 
      • Methods inherited from class java.lang.Object

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

      • PoisonRunnable

        public PoisonRunnable(java.lang.Runnable lastStep)
        Creates a new PoisonRunnable that will run the given runnable when it is called.
        Parameters:
        lastStep - the runnable to call when this runnable is finally called.
      • PoisonRunnable

        public PoisonRunnable(java.util.concurrent.CountDownLatch latch)
        Creates a new PoisonRunnable that will call the CountDownLatch.countDown() method on the given latch when its run method is finally called.
        Parameters:
        latch - the latch to decrement
      • PoisonRunnable

        public PoisonRunnable(java.util.concurrent.CyclicBarrier barrier)
        Creates a new PoisonRunnable that will call the CyclicBarrier.await() method of the given barrier when its run method is finally called.
        Parameters:
        barrier - the barrier to wait on.
      • PoisonRunnable

        public PoisonRunnable()
        Creates a new PoisonRunnable that will do nothing when its run method is called.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.