java - How is a thread in blocked state caused by waiting on a objects lock handled by the JVM -
i have seen there different ways thread blocked state. im interested know happens after thread in blocked state. how running state. if blocked sleep(time) moves runnable queue after time milli secs. if blocked on i/o operation gets runnable queue once done. how runnable queue when waiting on objects lock. how know lock on ocject waiting available. can 1 explain internals of how blocked thread on i/o works. please correct me if understanding on of above topics isn't right..
thank
how runnable queue when waiting on objects lock?
if thread blocked due trying enter synchronized
block, thread automatically marked runnable when other thread (holding lock) releases lock exiting synchronized
block of same object.
if current thread blocked due call someobject.wait()
, thread "released" when thread calls someobject.notify()
.
on bytecode level looks follows:
[load object, obj, onto operand stack] monitorenter // grab lock // stuff [load obj onto operand stack again] monitorexit // release lock
if else holds lock of obj
, thread hang on monitorenter
until other thread calls monitorexit
.
the exact details of how monitorenter
, monitorexit
should implement not specified jls. is, jvm/os dependent.
for further details, refer jls wait sets , notifications.
Comments
Post a Comment