CentOs カーネル バージョン 2.6.32 を使用しています。NIO を使用して transferTo(sendFile) の有無にかかわらずテストを行う予定です。私のテストは、1GBのファイルをあるディレクトリから別のディレクトリにコピーすることです。ただし、transferTo()を使用したため、パフォーマンスが大幅に向上することはありませんでした。ファイルからファイルへの sendFile が実際に Linux カーネルで機能するのか、それともファイルからソケットのみが機能するのか教えてください。sendFile を有効にする必要はありますか?
サンプルコード:
private static void doCopyNIO(String inFile, String outFile) {
FileInputStream fis = null;
FileOutputStream fos = null;
FileChannel cis = null;
FileChannel cos = null;
long len = 0, pos = 0;
try {
fis = new FileInputStream(inFile);
cis = fis.getChannel();
fos = new FileOutputStream(outFile);
cos = fos.getChannel();
len = cis.size();
/*while (pos < len) {
pos += cis.transferTo(pos, (1024 * 1024 * 10), cos); // 10M
}*/
cis.transferTo(0, len, cos);
fos.flush();
} catch (Exception e) {
e.printStackTrace();
}
}