现在要把收到的每个报文记录到单独的文件中,在做压力测试时发,FileOutputStream 中 close()方法执行需要的时间,随着系统持续压力测试时间的增长而增长,最后导致close()执行的时间在整个线程的执行时间占比越来越高,有没有什么方法改变一下这个情况。相关代码如下
[code="java"]
public static void write(byte[] msg, String fileName) {
if (fileName.indexOf(File.separator) != -1) {
String dirPath = fileName.substring(GatewayConstants.ZERO_INT, fileName.lastIndexOf(File.separatorChar));
createDir(dirPath);
}
FileOutputStream os = null;
try {
os = new FileOutputStream(createFile(fileName));
os.write(msg);
os.flush() ;
} catch (FileNotFoundException e) {
logger.error("fileNotFoundException exception"+fileName, e);
} catch (IOException e) {
logger.error("fileOutputStream closed exception", e);
}finally{
try {
if(os !=null)
os.close() ;
} catch (IOException e) {
logger.error("fileOutputStream closed exception", e);
}
}
}
[/code]