Re: Java running for ever on Linux



Marcelo wrote:
Actually, what I want to do is running many simulations in c++ on a server, but I want to control my c++ simulations with a Java Swing program (in order to show the results).

This is a much different statement than in your original posting. What do you really want? Are you probably mixing up terms like monitoring, and displaying results? Monitoring an application does not mean to display the results from it, it just means ensuring that it runs. Or do you want to monitor the results, but not the simulation programs?


Do you want to ensure that your simulations run "forever"? Then your problem is not running a Java program "forever". The Java program just has to pick up the results at some point in time and displays them. Which means, you start it when you want to see results.

If you want to be sure that something is running "forever" on Unix/Linux, consider adding a monitor process/script to inittab. It doesn't matter if this is a Java program or a script (I would go for the script, Java seems to be overkill for this for me). If the monitor program goes down / crashes, then initd can resurrect it, which is basically what you want. If you have written the script in the right way, and have designed a proper monitoring mechanism/interface it can pick up where it left, and continue to monitor your simulations.

To be really on the save side, you should also consider a hardware watchdog which restarts the OS if it apparently has crashed, hangs completely, etc.

Other "tricks" without an "application resurrection", like having a daemon to monitor your stuff are prone to fail. If such a daemon crashes there is no one to restart it. People sometimes think they are really clever and add a meta-monitor process to monitor the monitor process to monitor the application ... Which is pure nonsense.

If it is good enough to run a monitor process at regular intervals, instead of having it run permanently, you can consider to run one via cron. However, you should ensure that no two or more invocations of the monitor program overlap (e.g. if one invocation accidentally hangs).

All this is not a matter of Java. It is about knowing your operating system.

Regarding a Java application displaying the results of your simulations:

Since you haven't told us at all in which way and format they deliver their output it is impossible to tell how such an application should work. Do they write to files, do they write to sockets, do they use IPC, do they write to as named pipe? As a general remark, design your simulation programs in a way so that the output can be picked up whenever it is desirable. Be careful with data which needs to be accumulated by a display program in order to be useful. You don't want to have to process a weeks simulation output backlog first just to obtain a single data point in some graph.

/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
.



Relevant Pages

  • Re: atomic operations...
    ... No MUTEXS! ... the Monitor class in .NET isn't strictly speaking a Windows mutex function). ... Until you've measured and confirmed a genuine performance problem, IMHO you should not care so much about the specific synchronization mechanism used. ... The Java implementation trades synchronization in the class itself for synchronization in the memory manager. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: About synchronization methods
    ... The Java guys themselves admit that what Java has is ... not the true monitor but some low level means to implement a monitor- ... Once you name the language, please name the one true language that is worthy enough to implement the runtimes/virtual-machine for its holiness. ... In fact, as I've pointed out before in detail, the whole "language supported" synchronization model of Java is nothing more than very shallow semantic sugar over the standard library mutex and condition variable synchronization model. ...
    (comp.programming.threads)
  • Re: Block in synchronized mathod
    ... Where are those coming from in a Java ... malice, or possibly by design. ... but using coarse-grained monitors when you're waiting ... (remember you can use any old Object as a monitor). ...
    (comp.lang.java.help)
  • Java + Monitor Issues
    ... Whether I am on or off line, if I use Java web start or open a Java run applet, my monitor goes black. ... I am using Windows XP Home Ed's drivers for my monitor as they are newer than the drivers provided by Hitachi dating from 1999. ...
    (microsoft.public.windowsxp.general)
  • Re: Microsoft Java VM
    ... It isn't so much a security issue, as it was that MS was required to pull their Java VM from its web site, and even MSDN subscribers lost access to alot of packages that included it. ... These simulations will only run on the Microsoft Java VM ...
    (microsoft.public.windowsxp.security_admin)