commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <>
Subject Re: [vfs] usage questions
Date Wed, 08 Mar 2006 07:05:30 GMT
> 1) I call VFS.getManager() from a constructor of my file system wrapper
> class, and use that one FileSystemManager instance every time a CommonsVFS
> operation is executed. Is this the correct usage? Or should I get a
> different FileSystemManager for each request. I notice that the close()
> method is not on the FileSystemManager interface.
Using VFS.getManager() is the correct use, and a "soft reference" cache
tries to keep memory clean.
I use it in our web-app the same way.
Though, there is noting bad with instantiating the FileSystemManager
manual for every request - beside the fact that it is a hevyweight

> 2) If you can use the same FileSystemManager instance across multiple calls,
> do you need to periodically free unused resources?
In theory not, but VFS creates a vfs_temp directory where you should
setup some cron job to remove old files.
Sometimes (or often ;-) ) not all files are deleted.
> 3) Do you only need to close a FileObject when you have retrieved the
> content, or should close it after any operation.
Its sufficient to close a FileObject after you have done some stream
(create file/output/input) operations. For this you can use the .close()
method of the stream instance.
Though, when you use the VFS.getManager() stuff its sometimes required
(e.g. when you monitor a file) to close() the FileObject to synchronize
the internal state with the filesystem.

> Sorry if these seem like silly questions, but the documentation seems a
> little unclear. It says in the documentation that "You should make sure that
> you call close() on the manager when you are finished with it." Is this for
> all methods of retrieval and configuration, or only when you create and configure it
If you use a single instance for all threads (VFS.getManager()) then you
should NOT call close() as this will affect other threads. If you create
your own manager on a e.g. per-request basis you are safe to call
close() on the manager, and thus you can be sure all resources were freed.

Hope that helps!

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

View raw message