Please explain initialization safety as spelled out in Java memory model

前端 未结 2 1800
你的背包
你的背包 2020-12-13 20:20
  1. Can some one explain initialization safety as required by Java memory model ?
  2. How does the final fields help in achieving
2条回答
  •  佛祖请我去吃肉
    2020-12-13 20:55

    1. Initialization safety allows properly constructed immutable objects to be shared safely across threads without using synchronization, irrespective of even if they published using a data race.

    2. Objects having final field, initialization safety prevent reordering any part of construction with the initial load of a reference to that object.

提交回复
热议问题