开发者

FileLock with Tomcat Server and BlazeDS

开发者 https://www.devze.com 2023-01-27 20:18 出处:网络
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 filechann

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(); 

}
0

精彩评论

暂无评论...
验证码 换一张
取 消