问题描述
我有一个使用负载均衡器在群集模式下运行的Web应用程序。
它包含两个只对一个DB进行寻址的tomcats(T1和T2)。
T2是安装到T1的nfs。这是两个节点之间唯一的dofference。
我有一个生成一些文件的java方法。如果请求
在T1上运行没有问题,但如果请求在节点2
上运行,我会得到如下异常:
java.io.IOException:java.io.FileOutputStream.close0(本机方法)中的参数
无效java.io.FileOutputStream.close上的
(FileOutputStream.java:279 )
相应的代码如下:
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();
}
此异常出现在fileOut.close()
任何提示?
Luis
最后我找到了原因。
首先我注意到并非总是这个异常在同一点上来是
。
有时是
java.io. IOException:java.io.FileOutputStream.close0(本机方法)中的参数
无效java.io.FileOutputStream.close上的
(FileOutputStream.java:279)
^^^^^
有时是
java.io.IOException:无效的参数$ b java.io.FileOutputStream.writeBytes(本地方法)$ b $ java.io.FileOutputStream.write $(b)$ File $ $ $ $ $ $ $ $ $ >
因此问题不是java问题。甚至不是NFS问题。
问题是基础文件系统类型,它是一个DRBD
文件系统。
在shell上测试如果正在写一个小的
文件,则跨节点写入。即:
在nfs挂载节点上
cd / tmp
日期> / shared / path-to-some-not-mounted-dir / today
将起作用
但是
cat myBigFile> / shared / path-to-some-not-mounted-dir / today
将传递以下错误
cat:写错误:无效参数
因此解决方案是使用其他类型的文件系统,例如gfs。
I have a web application running in cluster mode with a load balancer.It consists in two tomcats (T1, and T2) addressing only one DB.T2 is nfs mounted to T1. This is the only dofference between both nodes.
I have a java method generating some files. If the requestruns on T1 there is no problem but if the request is running on node 2I get an exception as follows:
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()
Any hint?
Luis
解决方案 Finally I found the reason.First I've notices that NOT always this exception comesat 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) ^^^^^
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. Not even a NFS problem.The problem is the underlying File System type which is an DRBDfile system.
Testing at a shell to write across the nodes works if one is writing a smallfile. I.e:
at the nfs mounted node
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.
这篇关于java.io.IOException:参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!