Volatile or synchronized for primitive type?

前端 未结 5 1513
栀梦
栀梦 2021-02-04 06:52

In Java, assignment is atomic if the size of the variable is less than or equal to 32 bits but is not if more than 32 bits.

What (volatile/synchronized) would be more ef

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 07:20

    KDSRathore, you can use some explicit locks, or make some dummy Object object = new Object() , on which you synchronize in setter/getter of that double

提交回复
热议问题