• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

threads synchronization problem

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have 2 questions.

Q1. now the definition of wait() function is like this : tells the calling thread to give up monitor and go to sleep until some other thread enters the same monitor and calls notify().
Now in this program two threads(One related to consumer and one to producer) use the same object q in get and put respectively. So is there only one monitor existing for the object q, which is entered when any thread uses a function involving q?

Q2 Here the Consumer waits until Producer notifies it, but the Producer also waits until the consumer notifies it? Who starts first?
In the output, Producer comes first but how?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be forthright when crossposting to other sites.
 
Abhay Saini
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I posted this at Stackoverflow.com too
But i want to know as many opinions as possible.
Sorry if anyone is offended.
I will tell if I like any answer at that site so that your time is not wasted
 
Abhay Saini
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the 2nd question
but not the first one?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhay Saini wrote:I posted this at Stackoverflow.com too
But i want to know as many opinions as possible.


No problem, but when you do that, please say that you've also posted it somewhere else and include a link, so that people don't have to waste time answering the question when it has already been answered somewhere else.
 
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:
No problem, but when you do that, please say that you've also posted it somewhere else and include a link, so that people don't have to waste time answering the question when it has already been answered somewhere else.


Well that is ofcourse what he wants. If you post a question at several places on the net then you get some responses. If 2 or more people give the same response while they respond to a message on a different forum, then these responses have some value.

I understand that for some more basic things this is not necessary and desirable, but if the question is more advanced these equal responses would give me a good feeling to look in such direction...
 
Greenhorn
Posts: 13
Chrome Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Please be forthright when crossposting to other sites.



I think that's his right. I got no problem with that.

@Abhay: Can you try this?



I renamed "sse" to "hasData" in order to make it more clear:
+ consumer waits for data.
+ producer puts data in, then notify(), and waits for consumer.
+ consumer handles the data, then notify().
+ procedure ends.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic