"Translation" What exactly does the Finalize method do?

Source: Internet
Author: User

The following are the descriptions in the JDK:

Called by the garbage collector on a object when garbage collection determines that there is no more references to the O Bject. A Subclass overrides the finalize method to dispose of the system resources or to perform and other cleanup.


When the garbage collector discovers that an object does not have any references, it calls the Finalize method of the object's class. Subclasses rewrite the Finalize method, typically to handle system resources or do other cleanup work.


The general contract of this is, it is invoked if and when the finalize Java. Virtual machine had determined that there was no l Onger any means by which this object can is accessed by any of the thread that have not yet died, except as a result of a action Taken by the finalization of some and other object or class which are ready for be finalized. The method may take any finalize action, including making this object available again to other threads; the usual purpose of< c3/>, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the Finalize method for a object, represents an Input/output connection might perform explicit I/O trans Actions to break the connection before, the object is permanently discarded.


In general, the Finalze method is called when the Java Virtual Machine discovers that no active thread can refer to an object that has already been executed by the finalize. In the Finalze method, you can do anything, or even let the object be referenced by another thread, but generally the purpose of the Finalize method is to do some cleanup before the object is actually recycled. For example, an object that represents an input/output connection, its Finalize method may interrupt the corresponding I/O connection before it is recycled.


The finalize method of class Object performs no special action; it simply returns normally. Subclasses of May Object override this definition.


The Finalize method of the object class does nothing but simply returns. The subclass of object can override this method.


The Java programming language does not guarantee which thread would invoke the finalize method for any given O Bject. It's guaranteed, however, that's the thread that invokes finalize'll not being holding any user-visible synchronization lock s when the finalize is invoked. If an uncaught exception was thrown by the Finalize method, the exception was ignored and finalization of that object Termin Ates.


The Java language does not guarantee which thread will call the Finalize method. However, the thread that calls the Finalize method is guaranteed to hold any user-visible synchronization lock when finalize is called. If a failed catch exception is thrown in the Finalize method , the exception is ignored and the Finalize method aborts.


After finalize the method have been invoked for a object, no further action is taken until the Java Vsan has again Determined that there was no longer any means by which the object can be accessed by any thread that have not yet died, Inc Luding possible actions by other objects or classes which is ready-to-be-finalized, at-which point the-object may disc Arded.


Once an object's Finalize method is called, the object cannot be referenced again by any of the active threads, and the object can no longer do anything, including those objects or classes that have executed the Finalize method until they are reclaimed by the Java virtual machine.


The finalize method is never invoked more than once to a Java virtual machine for any given object.


A Finalize method for a particular object is never called more than once by a Java virtual machine.


Any exception thrown by the finalize method causes the finalization of this object to being halted, but was other Wise ignored.


Any exception thrown by the Finalize method will cause the Finalize method to abort, but this will also be ignored. (It should be said that, although the exception was thrown, finalize aborted, unable to continue execution, but after this, the object will not be able to be manipulated until it is reclaimed by the Java Virtual machine.) )


"Translation" What exactly does the Finalize method do?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.