Java: Is volatile / final required for reference to synchronized object?

后端 未结 5 803
陌清茗
陌清茗 2021-01-04 02:52

This seems a pretty basic issue, but I cannot find a clear confirmation.

Let\'s say I have a class properly synchronized in itself:

public class Sync         


        
5条回答
  •  Happy的楠姐
    2021-01-04 03:42

    Two things to keep in mind here for understanding:

    1. Racing for your reference variable has no conceptual difference from that of a member field.
    2. Sharing a reference variable requires careful handling of safe publication

提交回复
热议问题