- if (!Files.exists(lockFile))
- Files.createFile(lockFile);
-
- raLockFile = new RandomAccessFile(lockFile.toFile(), "rw");
- lock = raLockFile.getChannel().tryLock();
+ try {
+ lockFileChannel = lockFile.getFileSystem().provider().newFileChannel(lockFile,
+ EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE));
+ } catch (FileAlreadyExistsException e) {
+ throw new ProCoreException("The database in folder " + folder.toAbsolutePath() + " is already in use!", e);
+ }
+
+ lock = lockFileChannel.tryLock();