Threads - Why a Lock has to be followed by try and finally

前端 未结 6 2220
北荒
北荒 2020-12-03 13:09

A Lock is always followed by a try/finally block, why?

ReentrantReadWriteLock readWriteLockBitmap = new ReentrantReadWriteLock();
Lock read = readWriteLockBi         


        
6条回答
  •  盖世英雄少女心
    2020-12-03 13:11

    To make sure that whatever happens, even if an exception is thrown, you will still unlock the locked stream before leaving the method.

提交回复
热议问题