aspose file tools
The moose likes Threads and Synchronization and the fly likes Accessing Two queue's one by one Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Accessing Two queue Watch "Accessing Two queue New topic
Author

Accessing Two queue's one by one

S Babs
Greenhorn

Joined: Apr 16, 2003
Posts: 18
I need to run a "Starter class" which will start two threads. These threads start filling the data continously in their own queue objects.
When Starter is triggered, it should be able to pick one of the queue (by reference), by stopping one thread (while other is running) and give the pointer reference of this queue to some other object.
Next Empty this queue and this queue is ready back to get filled by the "Thread".
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 1855

First things first. When pluralizing a word, such as queue, it is not necessary to use an apostrophe. Yes, listening to my grammar pedantry is the price of my answering your question.
Sadly, my answer to your actual question may be somewhat impaired by the fact that I don't find the question completely coherent. I can glean that you have a thread that is filling a queue, and you may want to pause that thread. Here's how I would do it:

Is that what you were looking for? Does it make sense? It may be a bit overly complex with the two flags, but I worry about race conditions. Let us know if you have further questions!
 
 
subject: Accessing Two queue's one by one
 
Threads others viewed
Question 13 chapter 9 of k&B
help in having 'n' BlockedQueues and 'm' threads
about notify() and wait()
Question on Threads
doubt regarding threads
IntelliJ Java IDE