Why would you ever implement finalize()?

前端 未结 21 2665
耶瑟儿~
耶瑟儿~ 2020-11-22 16:50

I\'ve been reading through a lot of the rookie Java questions on finalize() and find it kind of bewildering that no one has really made it plain that finalize()

21条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 17:23

    To highlight a point in the above answers: finalizers will be executed on the lone GC thread. I have heard of a major Sun demo where the developers added a small sleep to some finalizers and intentionally brought an otherwise fancy 3D demo to its knees.

    Best to avoid, with possible exception of test-env diagnostics.

    Eckel's Thinking in Java has a good section on this.

提交回复
热议问题