java reference 作用_java Reference 中的 next 成员变量的作用是什么

/* A Reference instance is in one of four possible internal states:

*

* Active: Subject to special treatment by the garbage collector. Some

* time after the collector detects that the reachability of the

* referent has changed to the appropriate state, it changes the

* instance's state to either Pending or Inactive, depending upon

* whether or not the instance was registered with a queue when it was

* created. In the former case it also adds the instance to the

* pending-Reference list. Newly-created instances are Active.

*

* Pending: An element of the pending-Reference list, waiting to be

* enqueued by the Reference-handler thread. Unregistered instances

* are never in this state.

*

* Enqueued: An element of the queue with which the instance was

* registered when it was created. When an instance is removed from

* its ReferenceQueue, it is made Inactive. Unregistered instances are

* never in this state.

*

* Inactive: Nothing more to do. Once an instance becomes Inactive its

* state will never change again.

*

* The state is encoded in the queue and next fields as follows:

*

* Active: queue = ReferenceQueue with which instance is registered, or

* ReferenceQueue.NULL if it was not registered with a queue; next =

* null.

*

* Pending: queue = ReferenceQueue with which instance is registered;

* next = this

*

* Enqueued: queue = ReferenceQueue.ENQUEUED; next = Following instance

* in queue, or this if at end of list.

*

* Inactive: queue = ReferenceQueue.NULL; next = this.

*

* With this scheme the collector need only examine the next field in order

* to determine whether a Reference instance requires special treatment: If

* the next field is null then the instance is active; if it is non-null,

* then the collector should treat the instance normally.

*

* To ensure that a concurrent collector can discover active Reference

* objects without interfering with application threads that may apply

* the enqueue() method to those objects, collectors should link

* discovered objects through the discovered field. The discovered

* field is also used for linking Reference objects in the pending list.

*/

我把比较完整的注释贴上来了,这里可以知道流程的转换过程。

但是具体的工作细节,这个估计只有熟悉具体GC回收机制的人才能解答了。

等待大神吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值