40.

prev next contents
monitorexit

leave synchronized region of code

Jasmin Syntax
     monitorexit 
Stack

Before

After
objectref
...
...

Description

This releases an exclusive lock that was previously obtained using monitorenter for the object objectref. If other threads are waiting for the object to become unlocked, one of the waiting threads will be able to acquire a lock on the object and proceed.

Note that a single thread can lock an object several times - the runtime system maintains a count of the number of times that the object was locked by the current thread, and only unlocks the object when the counter reaches zero (i.e. when the number of monitorenters and monitorexits applied to a given object are equal).

The monitorenter/monitorexit mechanism is used by the Java synchronized statement to coordinate access to an object among multiple threads.

Exceptioms

NullPointerException - objectref is null.

IllegalMonitorStateException - objectref was not previously locked by the current thread.

Bytecode

Type

Description
u1
monitorexit opcode = 0xC3 (195)
See Also

monitorenter


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine
Java Virtual Machine (Java Series)
ISBN: 1565921941
EAN: 2147483647
Year: 1996
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net