作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我们知道,线程ReferenceHandler负责将待处理的Reference实例入队到ReferenceQueue,参见Reference$ReferenceHandler.run()中的这段代码:
public void run() {
for (;;) {
Reference r;
synchronized (lock) {
if (pending != null) {
r = pending;
Reference rn = r.next;
pending = (rn == r) ? null : rn;
r.next = r;
} else {
try {
lock.wait();
} catch (InterruptedException x) { }
continue;
}
}
// Fast path for cleaners
if (r instanceof Cleaner) {
((Cleaner)r).clean();
continue;
}
ReferenceQueue q = r.queue;
if (q != ReferenceQueue.NULL) q.enqueue(r);
}
}
}
如果pending queue为null,那么这个线程正在等待lock;
我的问题是什么时候通知这个线程?待定实例何时被修改?
最佳答案
来自代码
/* Object used to synchronize with the garbage collector. The collector
* must acquire this lock at the beginning of each collection cycle. It is
* therefore critical that any code holding this lock complete as quickly
* as possible, allocate no new objects, and avoid calling user code.
*/
static private class Lock { };
private static Lock lock = new Lock();
这意味着收集器将在完成并需要 ReferenceHandler 唤醒时 notify()
。
关于java - 何时通知 ReferenceHandler 线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8181347/
我们知道,线程ReferenceHandler负责将待处理的Reference实例入队到ReferenceQueue,参见Reference$ReferenceHandler.run()中的这段代码:
我正在使用 Blazor(托管)并希望在将结果发送回客户端时保留引用。下面的示例并不真正需要引用保留,而是我的测试场景,用于更复杂的结构。 “员工”类在共享项目中定义。 WebAPI 方法返回一个 I
我的理解是,当您在对象模型中定义循环引用时,您可以使用此设置来解决出现以下错误的问题: JsonException: 检测到不支持的可能的对象循环。这可能是由于循环或对象深度大于最大允许深度 32。
我是一名优秀的程序员,十分优秀!