java unsafe park_java – Unsafe.park vs Object.wait

如果您是应用程序员,则不应该使用这些方法中的任何一种.

它们的级别太低,容易搞砸,不适合在图书馆外使用.

为什么不尝试使用更高级别的构造,如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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值