aspose file tools*
The moose likes Threads and Synchronization and the fly likes wait&block state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "wait&block state" Watch "wait&block state" New topic
Author

wait&block state

saravanan ragunathan
Ranch Hand

Joined: Aug 02, 2010
Posts: 84


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


"I Love Java Ranch"
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

may be you know about it..


will look like this to the compiler


SCJP6.0,My blog Ranchers from Delhi
Sudhakar Sharma
Ranch Hand

Joined: Apr 04, 2009
Posts: 71

Hi Shanky,

In this situation will the threads not notified ever?

help please

thanks
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051



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

Joined: Mar 17, 2010
Posts: 1051

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

Joined: Apr 04, 2009
Posts: 71

thank you shanky
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

You are Welcome
 
Consider Paul's rocket mass heater.
 
subject: wait&block state