如果您是应用程序员,则不应该使用这些方法中的任何一种.
它们的级别太低,容易搞砸,不适合在图书馆外使用.
为什么不尝试使用更高级别的构造,如java.util.concurrent.locks?
回答你的问题. park(…)直接在线程上工作.它将线程作为参数并将其置于休眠状态,直到在线程上调用unpark,除非已经调用了unpark.
它应该比Object.wait()更快,如果您知道需要阻塞/解除阻塞的线程,它将在监视器抽象上运行.
public native void unpark(Object thread)
Unblock the given thread
blocked on park, or, if it is not blocked, cause the subsequent call
to park not to block. Note: this operation is “unsafe” solely because
the caller must somehow ensure that the thread has not been destroyed.
Nothing special is usually required to ensure this when called from
Java (in which there will ordinarily be a live reference to the
thread) but this is not nearly-automatically so when calling from
native code.