为什么不应该这样做?由于执行垃圾回收时会调用终结器,为什么我们不能在这里添加持久化相关代码呢?
最佳答案
正如书中所解释的
Not only does the JLS provide no guarantee that finalizers will get executed promptly, it provides no guarantee that they'll get executed at all. It is entirely possible, even likely, that a program terminates without executing finalizers on some objects that are no longer reachable.
关于java - 有效的 Java - 永远不要依赖终结器来更新关键的持久状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31114238/