简体   繁体   English

Java:调用super.clone()方法,volatile int值未复制到克隆对象中

[英]Java: calling super.clone() method, volatile int value not copied in cloned object

I faced one production bug (it happened only once at least in last 1 year). 我遇到了一个生产错误(至少在过去1年中仅发生过一次)。 After investigation I can conclude that super.clone() method was unable to copy an "volatile int" value to the new cloned object . 经过调查,我可以得出结论, super.clone()方法无法将“ volatile int”值复制到新的克隆对象

Does anyone faced this problem ever? 有人遇到过这个问题吗?

clone() method is widely used in jdk libraries and this is a basic thing that clone method guarantees. clone()方法在jdk库中广泛使用,这是clone方法保证的基本功能。 Can this happen? 这会发生吗?

It's not safe to clone volatile data. 克隆易失性数据并不安全。 Please see this post for side effects of cloning. 请参阅这篇文章 ,了解克隆的副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM