Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Having confusion with Thread  RSS feed

 
Dhananjay Deshmukh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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?
 
Ole Sandum
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Campbell Ritchie
Sheriff
Posts: 53773
127
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!