问题
I've presented that problem as possible JDK bug: Is JDK ClassLoader.getResourceAsStream broken? (unclosed resources)
I'm reading properties (with some interval) from file by:
try (InputStream propertiesInputStream =
new ClassPathResource(FILENAME).getInputStream()) {
loadedProperties.load(propertiesInputStream);
}
but when I go to /proc/MY_PROCESS_ID/fd
and list opened resources I see my FILENAME
properties file opened even 100 times or more. This is risky as 1024 is default limit on most unix machines.
It decrases sometimes to 0 (looks like closed by finalize() with GC call).
Why that resources do not dissapear immediately after leaving try-with-resources block?
/proc/TOMCATPID/fd shows a lot of (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
I read this properties 2 times per minute, which is consist with about 1000 opened descriptors after several hours.
来源:https://stackoverflow.com/questions/28480938/spring-classpathresourcefile-getinputstream-not-releasing-resource-immediate