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) {
|
private void doPreallocationKernelCopy(RecoverableRandomAccessFile file) {
|
||||||
try {
|
try (RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw");){
|
||||||
RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw");
|
|
||||||
templateRaf.getChannel().transferTo(0, getMaxFileLength(), file.getChannel());
|
templateRaf.getChannel().transferTo(0, getMaxFileLength(), file.getChannel());
|
||||||
templateRaf.close();
|
|
||||||
} catch (ClosedByInterruptException ignored) {
|
} catch (ClosedByInterruptException ignored) {
|
||||||
LOG.trace("Could not preallocate journal file with kernel copy", ignored);
|
LOG.trace("Could not preallocate journal file with kernel copy", ignored);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|
|
@ -300,11 +300,11 @@ public class DiskBenchmark {
|
||||||
if (tmpFile.exists()) {
|
if (tmpFile.exists()) {
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
}
|
}
|
||||||
RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw");
|
try (RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw");) {
|
||||||
templateFile.setLength(size);
|
templateFile.setLength(size);
|
||||||
templateFile.getChannel().force(true);
|
templateFile.getChannel().force(true);
|
||||||
templateFile.getChannel().transferTo(0, size, raf.getChannel());
|
templateFile.getChannel().transferTo(0, size, raf.getChannel());
|
||||||
templateFile.close();
|
}
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue