org.hibernate.search.batchindexing
Class ProducerConsumerQueue<T>

java.lang.Object
  extended by org.hibernate.search.batchindexing.ProducerConsumerQueue<T>

public class ProducerConsumerQueue<T>
extends java.lang.Object

Implements a blocking queue capable of storing a "poison" token to signal consumer threads that the task is finished.

Author:
Sanne Grinovero

Constructor Summary
ProducerConsumerQueue(int producersToWaitFor)
           
ProducerConsumerQueue(int queueLenght, int producersToWaitFor)
           
 
Method Summary
 void producerStopping()
          Each producer thread should call producerStopping() when it has finished.
 void put(T obj)
          Adds a new object to the queue, blocking if no space is available.
 T take()
          Blocks until an object is available; when null is returned the client thread should quit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProducerConsumerQueue

public ProducerConsumerQueue(int producersToWaitFor)
Parameters:
producersToWaitFor - The number of producer threads.

ProducerConsumerQueue

public ProducerConsumerQueue(int queueLenght,
                             int producersToWaitFor)
Method Detail

take

public T take()
       throws java.lang.InterruptedException
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:
java.lang.InterruptedException

put

public void put(T obj)
         throws java.lang.InterruptedException
Adds a new object to the queue, blocking if no space is available.

Parameters:
obj -
Throws:
java.lang.InterruptedException

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.



Copyright © 2006-2010 Hibernate. All Rights Reserved.