标签: java
正如标题中所述,在下列情况下,调用return时是否释放了锁?
return
public void method(){ syncronized(lock){ for(int i=0; i<10; i++) if( something.get(i) == something_else) return; } more code... }
答案 0 :(得分:5)
是
A synchronized statement acquires a mutual-exclusion lock (§17.1) on behalf of the executing thread, executes a block, then releases the lock.
return声明completes the execution of the block。