The close method for releasing resources is provided in the urlclassloader of Java 7.

Source: Internet
Author: User

Java applications, especially large Java applications, usually need to dynamically load classes or jar. urlclassloader provides this function, which allows us to load in the following ways:

* File: (load from the file system directory)
* Jar package: (load from jar package)
* Http: (load from a remote HTTP Service)

A common problem is that after the class file or resources resource file is updated, We need to reload these classes or jar files. Theoretically, when the application clears references to the loaded objects, the garbage collector will collect these objects and then reload the new JAR file, create a new urlclassloader for loading. But there is a problem here,That is, we do not know when the Garbage Collector will collect unreferenced objects, especially in windows, because files opened in Windows cannot be deleted or replaced.

InJava 7 build 48In, urlclassloader provides the close () method to release all opened resources, which saves developers a lot of time to solve this problem.

Reference: https://blogs.oracle.com/CoreJavaTechTips/entry/closing_a_urlclassloader

Related Article

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.