嗨,我有一些使用块的代码
RandomAccessFile file = new RandomAccessFile("some file", "rw");
FileChannel channel = file.getChannel();
// some code
String line = "some data";
ByteBuffer buf = ByteBuffer.wrap(line.getBytes());
channel.write(buf);
channel.close();
file.close();
Run Code Online (Sandbox Code Playgroud)
但应用程序的具体内容是我必须生成大量临时文件,平均超过4000个(用于将Hive插入到分区表中).
问题是有时我会遇到异常
Failed with exception Too many open files
Run Code Online (Sandbox Code Playgroud)
在应用程序运行期间.
如果有任何方法告诉操作系统文件已经关闭并且不再使用了,为什么会这样
channel.close();
file.close();
Run Code Online (Sandbox Code Playgroud)
不会减少打开的文件数量.有没有办法在Java代码中执行此操作?
我已经增加了打开文件的最大数量
#/etc/sysctl.conf:
kern.maxfiles=204800
kern.maxfilesperproc=200000
kern.ipc.somaxconn=8096
Run Code Online (Sandbox Code Playgroud)
更新: 我试图消除这个问题,所以我分开了代码来调查它的每个部分(创建文件,上传到配置单元,删除文件).
使用"File"或"RandomAccessFile"类失败,但"打开的文件太多"除外.
最后我使用了代码:
FileOutputStream s = null;
FileChannel c = null;
try {
s = new FileOutputStream(filePath);
c = s.getChannel();
// do writes
c.write("some data");
c.force(true);
s.getFD().sync();
} catch (IOException e) {
// …Run Code Online (Sandbox Code Playgroud) 有没有办法做这个主题?
我的意思是理论上有可能吗?任何JasperReports Server可用的插头?
或者也许有一些其他的报告工具可以做类似的工作JasperReports Server?
在谷歌上找不到任何信息.