aspose file tools
The moose likes Threads and Synchronization and the fly likes An always running process for queue processing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "An always running process for queue processing" Watch "An always running process for queue processing" New topic
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'.
 
IntelliJ Java IDE
 
subject: An always running process for queue processing
 
Threads others viewed
Tried out samples and order of messages not maintained
Deleting JMS Messages from the QUEUE
Bad Thread management (and URL decoding)
Sequential request processing
Blocking queue Implementation
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture