• 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

Having confusion with Thread

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand the part where wait(), notify(), and notifyall() are to be called. What i dont understand is the output that the below code produces. Its from Java 9th reference.



Below is the output


I understand till the part when put is called, and wait() executes in put, thread is stopped, get is called and then wait() executes again inside get method . What i don't understand is why does the polling is carried out till the values are 5 and then exit? Is it based on the fact that the default value of thread-priority is 5 and must be achieved by each thread before it exits?
 
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Dhananjay.

I ran the code. It does not stop at 5. What makes you think it does?
 
Dhananjay Deshmukh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ole Kristian Sandum wrote:Hey, Dhananjay.

I ran the code. It does not stop at 5. What makes you think it does?



Yeah i got that. I saw it in book, but after posting the question i tried myself. I will try writing 3- 5 programs on my own to fully understand. Sorry i didnt pay enough attention
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by going through the Java™ Tutorials section. You would usually do better to look for high level locking objects rather than the old techniques with wait/notify. You can also look at books e.g. Java Concurrency in Practice by Brian Goetz, Peierls, Bloch et al, the appropriate chapter in Java: the complete reference by Schildt, etc etc.
 
reply
    Bookmark Topic Watch Topic
  • New Topic