What will happen if thread throws a Exception inside synchronised block

后端 未结 3 1977
北恋
北恋 2021-02-05 18:18

Consider multiple threads are trying to access critical section, what will happen one thread that occurs Exception inside a synchronized block it having wait() and notify() to

3条回答
  •  伪装坚强ぢ
    2021-02-05 19:12

    Probably you are thinking of locks in the same way as resources(Connections, I/O) but unlike resources lock will be released as soon as the executing Thread reaches the exit boundary of critical section(monitor/ synchronized block closing parenthesis) regardless of Exception being thrown.

    Refer: synchronized statement

    If execution of the Block completes abruptly for any reason, then the monitor is unlocked and the synchronized statement completes abruptly for the same reason.

提交回复
热议问题