+ private void openFileChannel() throws IOException {
+ if (fileChannel != null)
+ return;
+
+ fileChannel = new RandomAccessFile(new File(getFileName()), "rw").getChannel();
+ lock = fileChannel.tryLock();
+ if (lock == null) {
+ System.err.println("Config file is in use by another instance, waiting…");
+ lock = fileChannel.lock();
+ System.err.println("Config file lock acquired.");
+ }
+ }
+