慕村225694
Object.wait()JVM_MonitorWait根据ThreadReferencejavadoc ,功能是使用本机方法实现的:/** Thread is waiting - Object.wait() or JVM_MonitorWait() was called */public final int THREAD_STATUS_WAIT = 4;该方法的实现可以在jvm.cppand uses中找到ObjectSynchronizer::wait:JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)) JVMWrapper("JVM_MonitorWait"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); JavaThreadInObjectWaitState jtiows(thread, ms != 0); if (JvmtiExport::should_post_monitor_wait()) { JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); // The current thread already owns the monitor and it has not yet // been added to the wait queue so the current thread cannot be // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT // event handler cannot accidentally consume an unpark() meant for // the ParkEvent associated with this ObjectMonitor. } ObjectSynchronizer::wait(obj, ms, CHECK);JVM_ENDObjectSynchronizer::wait实现是 insynchronizer.cpp并委托给ObjectMonitor::waitin objectMonitor.cpp。如果您继续深入研究,您最终将获得依赖于平台的本机 Java 线程实现。在 Linux 上libpthread.so,这将最终处理线程状态的变化。