Spring ClassPathResource(file).getInputStream() not releasing resource immediately

↘锁芯ラ 提交于 2019-12-11 08:35:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!