mirror of https://github.com/apache/activemq.git
Fixing RandomAccessFile usage so that the file will be properly closed even if there is an exception
This commit is contained in:
parent
0dd806f43f
commit
351faf2699
|
@ -374,10 +374,8 @@ public class Journal {
|
|||
}
|
||||
|
||||
private void doPreallocationKernelCopy(RecoverableRandomAccessFile file) {
|
||||
try {
|
||||
RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw");
|
||||
try (RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw");){
|
||||
templateRaf.getChannel().transferTo(0, getMaxFileLength(), file.getChannel());
|
||||
templateRaf.close();
|
||||
} catch (ClosedByInterruptException ignored) {
|
||||
LOG.trace("Could not preallocate journal file with kernel copy", ignored);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
|
|
@ -300,11 +300,11 @@ public class DiskBenchmark {
|
|||
if (tmpFile.exists()) {
|
||||
tmpFile.delete();
|
||||
}
|
||||
RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw");
|
||||
templateFile.setLength(size);
|
||||
templateFile.getChannel().force(true);
|
||||
templateFile.getChannel().transferTo(0, size, raf.getChannel());
|
||||
templateFile.close();
|
||||
try (RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw");) {
|
||||
templateFile.setLength(size);
|
||||
templateFile.getChannel().force(true);
|
||||
templateFile.getChannel().transferTo(0, size, raf.getChannel());
|
||||
}
|
||||
tmpFile.delete();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue