为什么从java 9 PhantomReference java doc开始说它专门用于POST-mortem清理操作,尽管之前它已经过验证
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了为什么从java 9 PhantomReference java doc开始说它专门用于POST-mortem清理操作,尽管之前它已经过验证,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2327字,纯文字阅读大概需要4分钟。
内容图文
![为什么从java 9 PhantomReference java doc开始说它专门用于POST-mortem清理操作,尽管之前它已经过验证](/upload/InfoBanner/zyjiaocheng/705/949a2fd8825b4e629bdf19ab79452cef.jpg)
PhantomReference java doc for java 8及更少看起来像这样:
Phantom reference objects, which are enqueued after the collector
determines that their referents may otherwise be reclaimed. Phantom
references are most often used for scheduling pre-mortem cleanup
actions in a more flexible way than is possible with the Java
finalization mechanism. If the garbage collector determines at a
certain point in time that the referent of a phantom reference is
phantom reachable, then at that time or at some later time it will
enqueue the reference.In order to ensure that a reclaimable object remains so, the referent
of a phantom reference may not be retrieved: The get method of a
phantom reference always returns null.Unlike soft and weak references, phantom references are not
automatically cleared by the garbage collector as they are enqueued.
An object that is reachable via phantom references will remain so
until all such references are cleared or themselves become unreachable
PhantomReference java doc for java 9及更高版看起来像这样:
Phantom reference objects, which are enqueued after the collector
determines that their referents may otherwise be reclaimed. Phantom
references are most often used to schedule post-mortem cleanup
actions. Suppose the garbage collector determines at a certain point
in time that an object is phantom reachable. At that time it will
atomically clear all phantom references to that object and all phantom
references to any other phantom-reachable objects from which that
object is reachable. At the same time or at some later time it will
enqueue those newly-cleared phantom references that are registered
with reference queues.In order to ensure that a reclaimable object remains so, the referent
of a phantom reference may not be retrieved: The get method of a
phantom reference always returns null.
在Java 9中PhantomReference行为有什么变化吗?还是只是java创始人重新思考那个阶级的奉献?
解决方法:
从Java 9开始,PhantomReference(PR)就是automatically cleared.你看到的是由于这种变化而导致的Javadoc变化.
在Java 9之前,PR引用的对象保持活动,即使它的get()将返回null.因此,在公关本身死亡之前,指示物在技术上是活的,尽管你无法获得它的参考.这种行为的好处不是很清楚.无论如何,公关处理将是“预先清理”.
在Java 9之后,PR在排队之前被清除(就像其他类型的弱/软refs一样),在由应用程序代码处理PR之前,指示对象本身已经完全死亡,这将是“事后清理”.
内容总结
以上是互联网集市为您收集整理的为什么从java 9 PhantomReference java doc开始说它专门用于POST-mortem清理操作,尽管之前它已经过验证全部内容,希望文章能够帮你解决为什么从java 9 PhantomReference java doc开始说它专门用于POST-mortem清理操作,尽管之前它已经过验证所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。