Reputation: 97
From my application, there are about 10535 threads created and each thread makes a soap call to get a response
Below is the error trace. Is this due to the server which couldn't handle this many requests? If it is, how do I resolve that?
[SOAPException: faultCode=SOAP-ENV:Client; msg=Error opening socket: java.net.SocketException: Too many open files; targetException=java.lang.IllegalArgumentException: Error opening socket: java.net.SocketException: Too many open files]
at org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnection.java:354)
at org.apache.soap.messaging.Message.send(Message.java:123)
Upvotes: 0
Views: 754
Reputation: 718788
The root cause of your problem is this:
From my application there are about 10535 threads ...
That is simply crazy. There is no way that you are going to get improved performance by running huge numbers of threads. Quite the reverse probably, because each one of those threads has a thread stack and objects on the heap. And the overheads of all of that memory, the GC overhead of that many live objects, the thread context switching, the contention, etc will be significant.
And each one of thos threads has a Socket, consuming a file descriptor AND resources in the kernel.
I recommend that you use a work queue and a bounded pool of worker threads. The simple way to do this is to use an ExecutorService
; read the javadocs
If you really insist on doing it that way, you will need to read up on how to increase the OS-level number of open files per process. The solution(s) depend on your OS. But the limit is being enforced by the OS not by Java, and you cannot solve it within the JVM.
See also:
Upvotes: 2