java.io.Exception: Too many open files on sun OS 5.6  
Author Message
gertschumann





PostPosted: 2004-7-1 17:51:00 Top

java-programmer, java.io.Exception: Too many open files on sun OS 5.6 I'm operating on sun OS 5.6
I ping a host every 10 seconds to get knowlegde wheather it is running
or not. After about one and a half hour I get this Exception:
java.io.IOException: Too many open files
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:546)
at java.lang.Runtime.exec(Runtime.java:413)
at java.lang.Runtime.exec(Runtime.java:356)
at java.lang.Runtime.exec(Runtime.java:320)
at de.optimare.VRX8100.MainControl.pingRecorder(MainControl.java:226)
... and so on.

I set rlim_fd_max = 1024 in /etc/system
I tried to set the ulimit -n 1024 in my script

but it had no effect.

Here is my code: The pingRecorder is called every 10 seconds from a
swing.Timer.
runtime is the Runtime.getRuntime().

// used on unix system
private void pingRecorder() {
logDate = new Date();

try {
ping = runtime.exec(pingPath);
ping.waitFor();
exitValue = ping.exitValue();
switch (exitValue) {
case 0:
// stop the ping timer
if (pingTimer != null) {
pingTimer.stop();
}

if (! processIsInitialized) {
System.out.println(logDate.toString() + " Recorder alive. Now
wait " + initialWaitTime/1000 + " seconds to initialize");
//wait for recorder is booting
Thread.sleep(initialWaitTime);
// now init the VRX8100 process!
initProcess();
}

break;

case 1:
System.out.println(logDate.toString() + " Recorder off.
Memory: " + runtime.totalMemory());
break;
default:
System.out.println(logDate.toString() + " Recorder off.
Memory: " + runtime.totalMemory());
break;
}

} catch (IOException io) {
io.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}



I would be very happy if anyone knows about anything due to this
problem.
Is it a specific sun problem? Is it possible to control the number of
open files by Java?
Many thanks for any help
Gert
 
Raymond DeCampo





PostPosted: 2004-7-2 8:19:00 Top

java-programmer >> java.io.Exception: Too many open files on sun OS 5.6 Gert Schumann wrote:
> I'm operating on sun OS 5.6
> I ping a host every 10 seconds to get knowlegde wheather it is running
> or not. After about one and a half hour I get this Exception:
> java.io.IOException: Too many open files
> at java.lang.UNIXProcess.forkAndExec(Native Method)
> at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
> at java.lang.Runtime.execInternal(Native Method)
> at java.lang.Runtime.exec(Runtime.java:546)
> at java.lang.Runtime.exec(Runtime.java:413)
> at java.lang.Runtime.exec(Runtime.java:356)
> at java.lang.Runtime.exec(Runtime.java:320)
> at de.optimare.VRX8100.MainControl.pingRecorder(MainControl.java:226)
> ... and so on.
>

>
>
> I would be very happy if anyone knows about anything due to this
> problem.
> Is it a specific sun problem? Is it possible to control the number of
> open files by Java?

Gert,

I suspect the problem is that the call to Runtime.exec() creates stream
handles for the standard input, output and error streams. You should
make sure to close these streams in your code. (Capture the Process
object returned from Runtime.exec() to get access to these streams.)

HTH,
Ray

--
XML is the programmer's duct tape.
 
Liz





PostPosted: 2004-7-2 8:25:00 Top

java-programmer >> java.io.Exception: Too many open files on sun OS 5.6
"Gert Schumann" <email***@***.com> wrote in message
news:email***@***.com...
> I'm operating on sun OS 5.6
> I ping a host every 10 seconds to get knowlegde wheather it is running
> or not. After about one and a half hour I get this Exception:
> java.io.IOException: Too many open files
> at java.lang.UNIXProcess.forkAndExec(Native Method)
> at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
> at java.lang.Runtime.execInternal(Native Method)
> at java.lang.Runtime.exec(Runtime.java:546)
> at java.lang.Runtime.exec(Runtime.java:413)
> at java.lang.Runtime.exec(Runtime.java:356)
> at java.lang.Runtime.exec(Runtime.java:320)
> at de.optimare.VRX8100.MainControl.pingRecorder(MainControl.java:226)
> ... and so on.
>
> I set rlim_fd_max = 1024 in /etc/system
> I tried to set the ulimit -n 1024 in my script
>
> but it had no effect.
>
> Here is my code: The pingRecorder is called every 10 seconds from a
> swing.Timer.
> runtime is the Runtime.getRuntime().
>
> // used on unix system
> private void pingRecorder() {
> logDate = new Date();
>
> try {
> ping = runtime.exec(pingPath);
> ping.waitFor();
> exitValue = ping.exitValue();
> switch (exitValue) {
> case 0:
> // stop the ping timer
> if (pingTimer != null) {
> pingTimer.stop();
> }
>
> if (! processIsInitialized) {
> System.out.println(logDate.toString() + " Recorder alive. Now
> wait " + initialWaitTime/1000 + " seconds to initialize");
> //wait for recorder is booting
> Thread.sleep(initialWaitTime);
> // now init the VRX8100 process!
> initProcess();
> }
>
> break;
>
> case 1:
> System.out.println(logDate.toString() + " Recorder off.
> Memory: " + runtime.totalMemory());
> break;
> default:
> System.out.println(logDate.toString() + " Recorder off.
> Memory: " + runtime.totalMemory());
> break;
> }
>
> } catch (IOException io) {
> io.printStackTrace();
> } catch (InterruptedException ie) {
> ie.printStackTrace();
> }
> }
>
>
>
> I would be very happy if anyone knows about anything due to this
> problem.
> Is it a specific sun problem? Is it possible to control the number of
> open files by Java?
> Many thanks for any help
> Gert

I have seen the 'too many open files' message in various
OS and languages. Seems like setting parameters doesn't
usually work for me so I just have to be careful to close
files when I am done with them.


 
 
gertschumann





PostPosted: 2004-7-2 16:50:00 Top

java-programmer >> java.io.Exception: Too many open files on sun OS 5.6 >
> Gert,
>
> I suspect the problem is that the call to Runtime.exec() creates stream
> handles for the standard input, output and error streams. You should
> make sure to close these streams in your code. (Capture the Process
> object returned from Runtime.exec() to get access to these streams.)
>
> HTH,
> Ray

Dear Ray,
Thanks, you solved the problem. It's working fine now!
Gert