Spring ClassPathResource (file) .getInputStream () does not release the resource immediately

I presented this problem as a possible JDK error: Is the JDK ClassLoader.getResourceAsStream broken? (unclosed resources)

I am reading the properties (at some intervals) from the file:

    try (InputStream propertiesInputStream = 
            new ClassPathResource(FILENAME).getInputStream()) {
                loadedProperties.load(propertiesInputStream);
            } 

but when I go to the /proc/MY_PROCESS_ID/fdlist of open resources, I see that my properties file is FILENAMEopen even 100 times or more. This is risky since 1024 is the default restriction for most Unix machines.

Sometimes it sometimes decreases to 0 (it looks like finalize () is closed with a call to GC).

Why don't these resources disappear immediately after exiting the try-with-resources block?

/ proc / TOMCATPID / fd shows a lot (currently> 1000):

lr-x------ 1 MyUserName TomcatUserName 64 Feb 13 01:04 973 -> /opt/project/apache-tomcat-7.0.27/conf/configurationServices.properties
lr-x------ 1 MyUserName TomcatUserName 64 Feb 13 01:04 974 -> /opt/project/apache-tomcat-7.0.27/conf/configurationServices.properties

2 , 1000 .

+1

All Articles