This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait&block state

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


consider that i created three threads and make a call to add method

consider a situation one thread is in wait state,second one is in blocked state
when runnable thread notify the waiting thread and releases the lock
will both waiting and blocked thread enter the runnable state
if it is,which one get preference to acquire the lock

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this example all thread will enter a wait state and never change. But if you add another function which notifies the threads then one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. Which is a direct quote from the javadoc.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be you know about it..


will look like this to the compiler
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shanky,

In this situation will the threads not notified ever?

help please

thanks
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


in case of threads nothing is guaranteed,but i think it should always remain in wait state.
after wait JVM should not moved further
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks to me that it will always remain in wait state and not moved further rest is dependent on JVM that how it behaves.
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you shanky
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic