在同步子句中抛出异常的副作用? [英] Side effects of throwing an exception inside a synchronized clause?

查看:124
本文介绍了在同步子句中抛出异常的副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何不明确的副作用从同步子句中引发异常?
锁是怎么回事?

Are there any unclear side effects to throwing an exception from within a synchronized clause? What happens to the lock?

private void doSomething() throws Exception {...}

synchronized (lock) {   
    doSomething();       
}


推荐答案

我看不到副作用

在所有情况下,锁定将被终止,异常也不例外(双关)。

The lock is guaranteed to be terminated in all cases, and an exception is no exception (pun intended).

这篇关于在同步子句中抛出异常的副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆