Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,

LOG.trace("Waiting for exclusive read lock to file: {}", target);

FileChannel channel = null;
RandomAccessFile randomAccessFile = null;
try {
randomAccessFile = new RandomAccessFile(target, "rw");
// try to acquire rw lock on the file before we can consume it
FileChannel channel = new RandomAccessFile(target, "rw").getChannel();
channel = randomAccessFile.getChannel();

boolean exclusive = false;
StopWatch watch = new StopWatch();
Expand Down Expand Up @@ -113,6 +116,24 @@ public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
// we were interrupted while sleeping, we are likely being shutdown so return false
return false;
}
} finally {
// Close channel
try {
if (channel != null) {
channel.close();
}
} catch (IOException ioe) {
LOG.warn("Unable to close channel for file " + file.getAbsoluteFilePath() + "!", ioe);
}

// Close file
try {
if (randomAccessFile != null) {
randomAccessFile.close();
}
} catch (IOException ioe) {
LOG.warn("Unable to close file " + file.getAbsoluteFilePath() + "!", ioe);
}
}

return true;
Expand Down