【发布时间】:2015-08-10 03:19:45
【问题描述】:
我想知道写在同步块中的代码,但是在 wait() 语句实际上是否以同步方式运行之后,因为在 wait() 期间,锁被放弃,一旦通知线程,它再次需要锁定。
public void process(){
synchronized(sharedObj){
try{
sharedObj.wait();
}catch(InterruptedException ex){
ex.printStackTrace();
}
// when wait is over do the line below runs in synchronized way. It is inside synchronized block but during call of wait(), lock was relinquished.
sharedObj.writeValue();
}
}
请帮我澄清我的疑问。
问候, 克里希纳
【问题讨论】:
标签: java multithreading synchronization wait