0

I am starting too many processes in Java using:

       Runtime.getRuntime().exec("java -ja myJar.jar")

When it reaches around 350 processes, I get an IO exception:

 Cannot run program "java": java.io.IOException: error=24, Too many open files
 Exception in creating process
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
    at java.lang.Runtime.exec(Runtime.java:610)
    at java.lang.Runtime.exec(Runtime.java:448)
    at java.lang.Runtime.exec(Runtime.java:345)

In each process I am using one database connection. I am running ubuntu 32 bit OS. But when I run:

   ulimit -u 

I can see that process limit is unlimited. What could be the problem?

4
  • Are you using a Virtual Server? Commented Feb 14, 2012 at 8:53
  • Check this answer to see if it helps Commented Feb 14, 2012 at 8:53
  • 1
    the world is limited, even if you set ulimit -u unlimited. it would be better if you change your program in order to execute more threads, instead of launching the same program more than 350 times! Commented Feb 14, 2012 at 8:55
  • Note that there are two separate 'too many open files' file limits, with separate error numbers: ENFILE (Too many files open in system) and EMFILE (Too many files open). Usually, but by no means guaranteed, EMFILE is errno=24. That's fixed by your process using fewer file descriptors. The system problem is unusual these days, but can occasionally happen; it is often indicative that either a reboot is needed or some processes need cleaning up. Commented Apr 18, 2012 at 13:57

3 Answers 3

1

All systems have their limits - sounds like you've hit your system's limit.

In linux, creating new processes consumes lots of inodes (like windows handles), which is a lot like a file handle. The only way around it is to allocate more via kernel settings (I don't know how offhand).

Have you considered starting lots of java Threads instead? They would consume a lot less system resources.

Sign up to request clarification or add additional context in comments.

1 Comment

inodes are not handles. inodes are identifiers of files in the file system. Handles, or fds (file descriptors) belong to open files. OP is running out of handles. The way around it is to call Process.waitFor() in this instance.
1

The problem is that you have too many files open, not too many processes in operation. To check the file limit do:

ulimit -n

It will commonly be 1024.

Check http://www.puschitz.com/TuningLinuxForOracle.shtml and search for ulimit for good instructions on changing this limit.

Comments

0

Running 350 JVM instances is not the normal way. Can you redesign and run 350 "main threads" within the same JVM. That is how servlet container works. All web applications are running in the same JVM.

PD. ulimit man pages says to see max. open files is ulimit -n.

1 Comment

I am using this design for a bench-marking. ulimit -n gives 1024

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.