| Author |
An always running process for queue processing
|
J.H.B. Oosterlaar
Ranch Hand
Joined: Sep 12, 2002
Posts: 41
|
|
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
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
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
|
 |
Leandro Oliveira
Ranch Hand
Joined: Nov 07, 2002
Posts: 298
|
|
|
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'.
|
 |
 |
|
|
subject: An always running process for queue processing
|
|
|