commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <>
Subject Re: [VFS] FileSystem close
Date Mon, 05 Jul 2004 09:00:33 GMT
Johan Lindquist wrote:

> Closing every file could be painful - at least to remember - but I 
> think  it would guarantee (more) that resources are released as 
> required.   Streams already require this and developers need to be 
> careful with  resources in general, so it is just a matter of 
> education ;)

Well, this is my opinion too.
I started by adding


to the DefaultFileSystemManager. Unhappily i have had to adapt the 
FileProvider too, so currently there are only a few fileSystems 
(including sftp) capable of this.
As said, you have to call close() on the fileObject to "detach" its 
native resources, but the real "free" only happens on this 
releaseUnusedResources call.

> Realise now how the filesystem close would not work in multi-threaded  
> environments either - unless it was made conditionally (using the 
> counter  you describe above) but then the cleanup method is definately 
> better ...

And there are more "threaded" aspects we have to take into account.
Consider the situation you are using VFS.getManager() and two threads 
reading/writing from/to the same fileobject. Now if one thread call 
close() on the fileObject the streams are closed for the other thread too.
Looks like we "stired up a hornet's nest".

> I can have a look at it (time  allowing) if you want some more feedback?

Testers are very welcome. Please use the current nightly build (or cvs 
source) and replace your close() by releaseUnusedResources(). However, 
it is a good idea to stick on the ThreadLocal version too.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message