This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Synchronizing thread woes! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Synchronizing thread woes!" Watch "Synchronizing thread woes!" New topic
Author

Synchronizing thread woes!

Rogelio Tristan
Greenhorn

Joined: Nov 16, 2004
Posts: 4
heres my code (runs and compiles fine!)




okay I figured out how to make a thread, and it puts numbers in a Queue, and then the consumer consumes the Queue. but my biggest problem is I need to have 2 consumers, one consumes 5, then the other consumes 5. how is that possible? I have thrown various counters in there but am still having quite some trouble, I'm not asking for just the answer, I'm asking for an explanation as to why the answer would be that. What do I do to make it comsume 5 first, then 5 to the next? any help is appreciated guys
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18510
    
  40

Step 1: Don't consuming anything until there is at least 5 items.

Change:


To:


Step 2: Consume 5 items without releasing the lock. I'll let you figure that out yourself.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rogelio Tristan
Greenhorn

Joined: Nov 16, 2004
Posts: 4
okay I appreciate the help and letting me try to figure it out myself.. let me know if I am hot or cold okay.. I was thinking putting the

Queue.store.wait();

statement 5 times; when I did it did it 5 times, then passed it back to the producer, then it went into this endless loop. so thats not it.


this has to do with the insertion of a
Queue.store.notify();
statement am i correct? perhaps get it to wait for 5 threads, then use notify to wake up the other thread again... hmm...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronizing thread woes!
 
Similar Threads
wait( ) and notify( )
Multithreaded Example... Where to put WAIT() , NOTIFY() advise please
Thread coma???
Threads, that processed two shared ArrayLists like Queue
threading access