• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io.FileNotFoundException (Too many open files)  RSS feed

 
Sunoo Varghese
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Could someone please help me on this. This problem occurs quite regularly and i've been sitting here scratching my head for quite sometime.
We've got an application that posts XML is an particular folder and after that our application reads the XMLs from that folder and processes the XML. However , of late, we've been noticing that in the error logs there have been lots of FileNotFoundException exceptions been thrown. The stack trace that we get is as follows..

java.io.FileNotFoundException: /XYZ/unix/cen/WebSphere/AppServer/POE/ORDER/InboundXml20060522191616451.xml (Too many open files)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:135)
at java.io.FileOutputStream.<init>(FileOutputStream.java:89)
at com.ford.pms.externalinterface.inbound.utils.FileIOUtils.writeToFile(FileIOUtils.java:25)
at com.ford.pms.externalinterface.inbound.utils.InboundRequestManager.processInterfaceRequest(InboundRequestManager.java:451)
at com.ford.pms.externalinterface.inbound.service.InboundSOAPReceiverServlet.doPost(InboundSOAPReceiverServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:721)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:374)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:118)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:134)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:239)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:106)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:154)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:317)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:391)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:274)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:144)

Any suggestion on what the problem could be? I believe that this problem does not occur often. And that it occurs only when there are lots of files to be processed. Because of this problem our application fails to update the information being posted at times.. We are using Solaris and Websphere Application Server..


Sunoo
 
Mandar Max
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code that is causing the problem? Especially the code used to read/write files. Are you using classloader to obtain a file resource?
 
Sunoo Varghese
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is the code that write the file to the location. I just noticed that the closing of the DataOutputStream has not been handled properly. Could that be the cause of this problem?
public static void writeToFile(String stFile, String stFileBody, String mfgCode) throws Exception {

DataOutputStream dataOs = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(stFile, false)));
if(!"VL".equals(mfgCode))
{
dataOs.writeUTF(stFileBody);
}
else
{
int count = 0;
while(count+4096 <= stFileBody.length())
{
dataOs.writeUTF(stFileBody.substring(count,count+4096));
count += 4096;
}
dataOs.writeUTF(stFileBody.substring(count,stFileBody.length()));
}
dataOs.close();
}

Sunoo
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the error "too many open files" is pretty self-explanatory. If you
really must have this many open files, then find out how you can make the
system allow you to do this (this is controlled by the OS not Java) or
come up with some pooling system, that will allow you to automatically
close and reopen files as needed. I have the feeling that your code has
a bug somewhere that is preventing it from closing files, which will
eventually lead to this, because there is no timeout on an open filehandle.
It is even possible that you have opened the same file often enough to
have caused this problem, simply by not closing previous instances, and then
opening the same file again.
[ May 23, 2006: Message edited by: Martin Simons ]
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My post overlapped yours, but yes, if you are not closing the files, that
is the problem.
 
Sunoo Varghese
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mandar & Martin.. Will try that out..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!