FileLock with Tomcat Server and BlazeDS
i have a tomcat/blazeDS application in with several users write to the same xml file. while they write i want to have开发者_运维百科 a file lock on that file. my first attempt was to get the filechannel of the file and establish a lock() to the file. But unfortunately there is always a OverlappingFileLockException if i try to do so cause there is always a new process for a new call to the blazeDS components.
Is there a possibility to store a FileLock within a session or a basic functionality of tomcat to lock files within a session.
Thnak you all
I solved it by using a ReentrentLock within a static class so i cannot access it while it is locked.
public class DataAccessUtil {
private static final ReentrantLock lock = new ReentrantLock();
...
public static void lockDataFolder() {
lock.lock(); // block until condition holds
}
public static void unlockDataFolder() {
lock.unlock();
}
精彩评论