Objects not being finalized and Finalizer thread not doing anything

我与影子孤独终老i 提交于 2019-12-04 05:28:46

We think it was related to the OpenJDK version 1.6.0_30. After upgrading to Oracle JDK 1.7.0_51, the problem disappeared. And it probably appeared after automatic update of openJDK, but we cannot confirm this either. We could not find a relevant bug report.

dimo414

The Finalizer thread has low-priority, and thus will spend a good amount of time WAITING rather than finalizing. I wouldn't conclude from that stack trace that the thread is blocked; it's simply relinquished control to other threads. It's instead likely you are introducing a pathological number of objects into the finalizer queue and the JVM simply can't keep up.

There are unfortunately far too many possible explanations for why this behavior changed between versions to identify an exact cause, but here's a possible explanation. Oracle's Java 7 has a a new, more efficient garbage collector. It's reasonable to imagine that lightened load on the GC means the finalizer queue gets more time on the processor, and is therefore able to keep up with the number of objects being added to it.

However regardless of the underlying cause the correct solution is to reduce your usage of finalizers. Except in very limited circumstances they introduce more problems than they solve, not the least of which is GC and memory overhead. If you ever find yourself investigating objects that are pending finalization cleanup you are constructing too many finalizable objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!