Why did Java and C# add intrinsic lock to every object?

前端 未结 4 639
悲&欢浪女
悲&欢浪女 2020-12-31 05:06

Making every object lockable looks like a design mistake:

  1. You add extra cost for every object created, even though you\'ll actually use it only in a tiny fract
4条回答
  •  春和景丽
    2020-12-31 05:35

    One benefit is automatic unlock on exit from synchronized block, even by exception.

提交回复
热议问题