jsat.utils
Class PoisonRunnable
- java.lang.Object
-
- jsat.utils.PoisonRunnable
-
- All Implemented Interfaces:
- java.lang.Runnable
public final class PoisonRunnable extends java.lang.Object implements java.lang.RunnableA helper class for using the reader / writer model to implement parallel algorithms. When using the aBlockingQueue, 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 theBlockingQueue.take()operations blocks until a value is added. If the queue is a queue ofRunnablejobs, 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, therun()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 thePoisonRunnable(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 theCountDownLatch.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 theCyclicBarrier.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 voidrun()
-
-
-
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 theCountDownLatch.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 theCyclicBarrier.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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG