Here\'s the scenario: I have a multi threaded java web application which is running inside a servlet container. The application is deployed multiple times inside the servlet
Using java.nio.channels.FileLock, with a ReadWriteLock.
If I were you, I'd hide the File, FileChannel and all FileOutputStream from all business code. Replaced with my own simple adapter class, like an DAO.
e.g.
abstract class MyWriter{
private FileChannel file;
public void writeSomething(byte[] b){
// get VM scope write lock here
// get file lock here
// do write
// release file lock
// release readwritelock lock
}
}