Contents | Prev | Next | Index

monitorenter

Operation

monitorenter
Enter monitor for object

Forms
monitorenter = 194 (0xc2)

Stack
..., objectref ...

Description
The objectref must be of type reference.

Each object has a monitor associated with it. The thread that executes monitorenter gains ownership of the monitor associated with objectref. If another thread already owns the monitor associated with objectref, the current thread waits until the object is unlocked, then tries again to gain ownership. If the current thread already owns the monitor associated with objectref, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with objectref is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1.

Runtime Exception
If objectref is null, monitorenter throws a NullPointerException.

Notes
For detailed information about threads and monitors in the Java Virtual Machine, see Chapter 8, "Threads and Locks."


Contents | Prev | Next | Index

Java Virtual Machine Specification (HTML generated by dkramer on February 25, 1997)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com