两套等待()和“()”方法,如果一对二读,则一对二读,要么在一段时间内,要么在接近二读完成。
如果我们使用这些方法的超负荷版本,即等待(长时间停用)和加入(长米),那么
In case of wait(long timeout), thread-1 will become runnable either by notify (or notifyall) or even timeout occurs (whichever is first).
在加入(长米)的情况下,在二读完成或时间(以先为准)时,二读即行即行。
因此,这两种执行之间的区别是什么?
有些人认为是:
- For wait(), we need to have the lock on the object we are waiting on. For join() these are not necessary.
- After executing wait(), the thread removes lock it obtained and re-gains the lock once it becomes running again. But what about join? Does a thread removes a lock after executing join if this was executed from a synchronized block (or method)?