?
Solved

"java.io.IOException: Too many open files" rlim_fd_cur set to max

Posted on 2005-03-03
1
Medium Priority
?
1,354 Views
Last Modified: 2013-12-27
I am getting the "java.io.IOException: Too many open files" error when
running some program on a Solaris 8.  Pls note, I have already set
ulimit to max.  How can I avoid this problem?  Thanks in advance for
answering my question.

Here is the output from "uname -a":

SunOS ax-pb2 5.8 Generic_108528-19 sun4u sparc SUNW,Ultra-5_10

Here is what I have on the /etc/system:

set rlim_fd_cur = 4096
set rlim_fd_max = 4096
0
Comment
Question by:cklh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 38

Accepted Solution

by:
yuzh earned 500 total points
ID: 13456469
Please have a look at the following Sun Doc:

#---------------------------------------------------------------------------------------------------------
Document Audience: PUBLIC
Document ID: 3379
Title: Technote 3379
Synopsis: Too many open files thrown when Runtime.exec() is invoked
Update Date: Mon Mar 05 00:00:00 MST 2001

--------------------------------------------------------------------------------

Document ID: 3379
Date Approved: 03/05/2001
Synopsis: Too many open files thrown when Runtime.exec() is invoked
OS Version: 8
Keywords:
IOException, Too many open files

Description:
I have encountered the following exception when I run the following program using Runtime.exec() on Solaris. How do I fix this problem? // ========= Exception Information ====== java.io.IOException: Too many open files at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.forkAndExec(Compiled Code) at java.lang.UNIXProcess.<init>(Compiled Code) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.execInternal(Compiled Code) at java.lang.Runtime.exec(Compiled Code) at java.lang.Runtime.exec(Compiled Code) at java.lang.Runtime.exec(Compiled Code) at TestPro.run(Compiled Code) at TestPro.main(TestPro.java:29) // ========= My Program ============ public class TestPro{ Runtime runtime = null; Process p = null; int exitValue = -1; public TestPro(){ runtime = Runtime.getRuntime(); }; public void run() { try { while (true) { p = runtime.exec("echo"); java.lang.Thread.sleep(1000); p.waitFor(); } } catch(Exception e) { e.printStackTrace(); } } public static void main(String s[]) { TestPro tp = new TestPro(); tp.run(); } }
Solution:
* The subprocess is not killed when there are no more references
 * to the <code>Process</code> object, but rather the subprocess
 * continues executing asynchronously.

This implies that a Process object can not be finalized. Also there is nothing
in the specification of waitFor() which implies that it is allowed to close the
I/O streams. The java code could read the process's output after it finishes.
Closing the process file descriptors should be done in the user code.

Add the following lines of code after calling p.waitFor();  

                   p.getInputStream().close();
                   p.getOutputStream().close();
                   p.getErrorStream().close();

This should allow you to run the test code indefinitely.

Note that increasing the file descriptor limit in ulimit will only postpone
the occurrence of the problem.

from:
http://sunsolve.sun.com/search/printfriendly.do?assetkey=1-30-3379-1
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question