| 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: 16689
|
|
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...
|
 |
 |
|
|
subject: Synchronizing thread woes!
|
|
|