Class PojoProducerConsumerQueue<T>
java.lang.Object
org.hibernate.search.mapper.pojo.massindexing.impl.PojoProducerConsumerQueue<T>
- Type Parameters:
T- produced type
Implements a blocking queue capable of storing
a "poison" token to signal consumer threads
that the task is finished.
- Author:
- Sanne Grinovero
-
Constructor Summary
ConstructorsConstructorDescriptionPojoProducerConsumerQueue(int producersToWaitFor) PojoProducerConsumerQueue(int queueLength, int producersToWaitFor) -
Method Summary
Modifier and TypeMethodDescriptionvoidEach producer thread should call producerStopping() when it has finished.voidAdds a new object to the queue, blocking if no space is available.take()Blocks until an object is available; when null is returned the client thread should quit.
-
Constructor Details
-
PojoProducerConsumerQueue
public PojoProducerConsumerQueue(int producersToWaitFor) - Parameters:
producersToWaitFor- The number of producer threads.
-
PojoProducerConsumerQueue
public PojoProducerConsumerQueue(int queueLength, int producersToWaitFor)
-
-
Method Details
-
take
Blocks until an object is available; when null is returned the client thread should quit.- Returns:
- the next object in the queue, or null to exit
- Throws:
InterruptedException- if interrupted while waiting
-
put
Adds a new object to the queue, blocking if no space is available.- Parameters:
obj- the object to add to the queue- Throws:
InterruptedException- if interrupted while waiting
-
producerStopping
public void producerStopping()Each producer thread should call producerStopping() when it has finished. After doing it can safely terminate. After all producer threads have called producerStopping() a token will be inserted in the blocking queue to eventually awake sleeping consumers and have them quit, after the queue has been processed.
-