Contents Prev Next Up


3.18 Monitors

monitorenter

 
monitorenter = 194
Enter monitored region of code

Stack: ..., objectref => ... 

objectref must be a reference to an object.

The interpreter attempts to obtain exclusive access via a lock mechanism to objectref. If another thread already has objectref locked, than the current thread waits until the object is unlocked. If the current thread already has the object locked, then continue execution. If the object is not locked, then obtain an exclusive lock.

If objectref is null, then a NullPointerException is thrown instead.

monitorexit

 
monitorexit = 195
Exit monitored region of code

Stack: ..., objectref => ... 

objectref must be a reference to an object.

The lock on the object released. If this is the last lock that this thread has on that object (one thread is allowed to have multiple locks on a single object), then other threads that are waiting for the object to be available are allowed to proceed.

If objectref is null, then a NullPointerException is thrown instead.


Contents Prev Next Up