Hi, This is the simple representation of the situation: a producer (Servlet) produces queue elements and enqueues the elements (the queue is a Singleton datastructure). A consumer dequeues the elements for processing. The produces could produce elements all the time (in a very extreme situation), and should always be able to enqueue. The consumer is a Thread that is always running. When the queue is empty, it calls yield(), if not it dequeues the first element and processes it. What I need to know, is it a normal Java situation, that the consumerthread is always running? The proces of enqueue and dequeue has to be asynchrone, so a consumer proces is needed to handle elements independantly. Thanks in advance! Jeroen
The Java way to to this is for the consumer to call wait(). The producer would call notify() to wake up the consumer after enqueuing a new item. Do a search for "consumer" or "producer" in this forum and I think you'll get plenty of hi(n)ts. - Peter
instead of calling yield() you could call wait(), if there is nothing to consume. Whenever a producer produces, you call notify() or notifyAll() to wake all waiting threads wake, 'because there is already resource to be consumed'.