I have written a java program which reads data from a com port in its own thread and puts it in a database. When exceptions occur (database or com) it restarts itself with runtime.exec. After a day or so the program sometimes freezes. I cannot keep track of when this occurs exactly but it seems to happen after a little while. Does one of you guys know what may be the problem? Thank !
-
How often does it listen to port or reading data? – Mohamed Saligh Nov 22 '10 at 10:15
-
1Would that mean that at some point you have your app running another copy of your app, which runs another copy of your app and so on (depending on the number of exceptions)? – extraneon Nov 22 '10 at 10:16
-
Possible duplicate of http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems – Raedwald Jan 29 '16 at 03:37
4 Answers
If you simply catch the IO exceptions, and do runtime.exec, you may get out of memory, due to too many JVMs... Are you sure the old program (and JVM) are completely gone when doing a new runtime.exec? That is, as @extraneon put it, are you sure your program is not creating another instance of your program, which in turn creates another instance of your program, ...?

- 413,195
- 112
- 811
- 826
Please refer here : http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/sys_hangs.html

- 12,029
- 19
- 65
- 84
Depending on how you implemented your software you may have a design issue.
If you use Runtime.exec() from a starter application, that would be fine. If you have something like:
try {
doStuff();
} catch(Throwable t) {
Runtime.exec( ... );
}
you will get more than one copy of your software running, each taking some resources and never giving those back. In such a case you should actually just clean up the failing thread and start a new thread (if possible).
Just to be clear, a starter app in my view is something with in the main not much more than:
while(true) {
Process p = Runtime.exec( your COM communication program );
if ( p.waitFor() == 0 { // Clean exit
break; // exit while loop.
}
// Otherwise p closed with an error and a new process should be started
// which is done in the next iteration of the loop
}

- 133,037
- 18
- 149
- 215

- 23,575
- 2
- 47
- 51
When you are starting the processes with Runtime.exec() are you consuming the stdout and stderr streams? If no, the application would freeze when it fills the OS buffer. Depending on how much output does the application produce and how often it throws exceptions, your numbers might vary.

- 3,293
- 3
- 31
- 46