I'm looking into using Apache Commons VFS for a project that will need to transfer files between local server and remote servers via ftp, sftp and https.
The standard usage examples are getting the FileSystemManager from a static method
FileSystemManager fsManager = VFS.getManager();
Is it safe to use the same FileSystemManager across multiple threads?
And a second question is about properly releasing resources in a finally block: I find the following methods in the Javadoc API:
But it's not clear to me which of these resources should typically be closed.
The filemanager and filesystem objects are supposed to be thread safe, however I would not bet my live on it. Some internal locking (especially around renames) depend on the instance of the FileObject, so you should not use a FileCache which does not keep those (i.e. the default cache is fine).
FileContent and streams should not be used concurrently (in fact FileContent.close() for example only acts on streams of the current thread).
There are some resource leaks in this area (hopefully all fixed in 2.1-SNAPSHOT).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With