Apache Commons VFS Security and Resource Management

I am learning Apache Commons VFS for a project that will need to transfer files between the local server and remote servers via ftp, sftp and https.

In standard use cases, a FileSystemManager is created from a static method

FileSystemManager fsManager = VFS.getManager(); 

Can I use the same FileSystemManager for multiple threads?

And the second question is the proper release of resources in the finally block: in the Javadoc API, I found the following methods:

But it is not clear to me which of these resources should usually be closed.

+7
vfs apache-commons-vfs
source share
2 answers

The file manager and file system objects must be thread safe, however I would not put my life on it. Some internal locking (especially around renaming) depends on the instance of the FileObject, so you should not use FileCache, which does not save them (i.e., the default cache is in order).

FileContent and streams should not be used at the same time (in fact, FileContent.close (), for example, only affects the streams of the current stream).

There are some resource leaks in this area (I hope everything is fixed in 2.1-SNAPSHOT).

+1
source share

VFS.getManager provides one manager, i.e. single access to the file system, so I do not recommend using it from a multi-threaded environment. You can create your own DefaultFileSystemManager and use the close method when you are done.

0
source share

All Articles