简体   繁体   English

java.io.IOException:参数无效

[英]java.io.IOException: Invalid argument

I have a web application running in cluster mode with a load balancer. 我有一个以集群模式运行的Web应用程序,带有负载均衡器。 It consists in two tomcats (T1, and T2) addressing only one DB. 它由两个tomcats(T1和T2)组成,只能处理一个DB。 T2 is nfs mounted to T1. T2是nfs安装到T1。 This is the only dofference between both nodes. 这是两个节点之间唯一的差异。

I have a java method generating some files. 我有一个java方法生成一些文件。 If the request runs on T1 there is no problem but if the request is running on node 2 I get an exception as follows: 如果请求在T1上运行没有问题,但如果请求在节点2上运行,我会得到如下异常:

java.io.IOException: Invalid argument
        at java.io.FileOutputStream.close0(Native Method)
        at java.io.FileOutputStream.close(FileOutputStream.java:279)

The corresponding code is as follows: 相应的代码如下:

for (int i = 0; i < dataFileList.size(); i++) {
    outputFileName = outputFolder + fileNameList.get(i);
    FileOutputStream fileOut = new FileOutputStream(outputFileName);                        
    fileOut.write(dataFileList.get(i), 0, dataFileList.get(i).length);
    fileOut.flush();
    fileOut.close();
}

The exception appears at the fileOut.close() fileOut.close()出现异常

Any hint? 任何提示?

Luis 路易斯

.profile设置此行解决了问题:

ulimit –n 2048

How large do dataFileList and fileNameList get? dataFileList和fileNameList有多大? You could be running out of file descriptors. 你可能会用完文件描述符。 It's odd that it happens on close(), though. 但它很奇怪它发生在close()上。

Finally I found the reason. 最后我找到了原因。 First I've notices that NOT always this exception comes at the same point. 首先我注意到并非总是这个例外出现在同一点上。

Sometimes was a java.io.IOException: Invalid argument at java.io.FileOutputStream.close0(Native Method) at java.io.FileOutputStream.close(FileOutputStream.java:279) ^^^^^ 有时是java.io.IOException:java.io.FileOutputStream.close上的java.io.FileOutputStream.close0(本地方法)中的无效参数(FileOutputStream.java:279)^^^^^

and sometimes was 有时是

java.io.IOException: Invalid argument
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:260)

Therefore the problem is NOT a java problem. 因此问题不是java问题。 Not even a NFS problem. 甚至不是NFS问题。 The problem is the underlying File System type which is an DRBD file system. 问题底层文件系统类型,它是DRBD文件系统。

Testing at a shell to write across the nodes works if one is writing a small file. 如果正在编写一个小文件,则在shell上进行测试以跨节点进行编写。 Ie: 即:

at the nfs mounted node 在nfs安装的节点上

cd /tmp
date > /shared/path-to-some-not-mounted-dir/today

will work

but

cat myBigFile > /shared/path-to-some-not-mounted-dir/today

will deliver the following error 将传递以下错误

cat: write error: Invalid argument

Therefore the solution is to use other type of file system, gfs for example. 因此解决方案是使用其他类型的文件系统,例如gfs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM