• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Synchronizing thread woes!

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rogelio Tristan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic