How do I keep a Java Application running at all times?


  1. Posts : 7
    POS Ready Windows 7 Embedded Standard SP1 32 bit
       #1

    How do I keep a Java Application running at all times?


    Hi,
    I am developing a Java based application and need to make sure that if it crashes, it comes back on. I tried setting it up as a service, but as it requires interaction with the user, the "Interactive Services Detection" is tripped when I try to bring it up.

    My thoughts right now are to have it update a text file periodically and have a service monitor that text file. If the file has not been updated, then the service runs a script which reopens the application... does anyone know if there is an easier way of doing this? (or if this will even work?)

    Thanks!
      My Computer


  2. Posts : 10,485
    W7 Pro SP1 64bit
       #2

    Create one user app and one service app. The service app checks on the status of the user app and restarts it - if need be.
      My Computer


  3. Posts : 7
    POS Ready Windows 7 Embedded Standard SP1 32 bit
    Thread Starter
       #3

    UsernameIssues said:
    Create one user app and one service app. The service app checks on the status of the user app and restarts it - if need be.
    Thanks UsernameIssues - do you happen to have a link to a 'how to'? This is my first time setting up a windows service... specifically, how do I monitor the user app?

    My experience with creating services thus far is using JSmooth to create an exe file from my executable jar file.
    Last edited by cr0ck3t; 30 Nov 2013 at 16:25.
      My Computer


  4. Posts : 10,485
    W7 Pro SP1 64bit
       #4

    Unfortunately, I don't write stuff in Java...
    So I won't be of much practical help, only theoretical.

    I'm not even sure that you need one app to be a service. You could just have two regular apps (one with a user interface and one without).
    Is there a Java function that lists all of the apps that are currently running?
    If so, then...
    ...have app1 start app2 if app2 is not running
    ...have app2 start app1 if app1 is not running.

    Put you user interface in ether app.
      My Computer


  5. Posts : 2,468
    Windows 7 Ultimate x64
       #5

    May I ask why do you think it's going to crash in the first place? Or why is so crucial that it comes back if it actually crashes? I'm thinking that if the program has an UI, then the user would notice that it has a problem and will restart it if that's important. Maybe making sure that an unexpected error will make the program crash in the most "loudly" way to alert the user can be a better option?

    Anyway, for the auto-restarting thing. As the program requires user interaction, making it a service is completely out of question (services are meant to run completely unattended without any UI, and since Vista that's not only encouraged, but enforced). Having two programs instead of one is a good idea, just normal programs not services, one of which launches the second, monitors it and re-opens in case of problems. The second instance will do all the real work.

    Have a look here for how to launch programs within Java: How do I run another application from Java? - Web Tutorials - avajava.com.
    Note that the runtime.exec call returns a Process object. You can use that returned object for monitoring the second program. The waitFor method seems a good options: Process (Java Platform SE 7)
    It should just wait for the second program to terminate, in any way, so after that you may attempt to launch it again.
      My Computer


  6. Posts : 4,161
    Windows 7 Pro-x64
       #6

    Careful how you set that up. You could send Windows into a close loop at shutdown.
      My Computer


  7. Posts : 10,485
    W7 Pro SP1 64bit
       #7

    Alejandro85 said:
    May I ask why do you think it's going to crash in the first place? Or why is so crucial that it comes back if it actually crashes? I'm thinking that if the program has an UI, then the user would notice that it has a problem and will restart it if that's important. Maybe making sure that an unexpected error will make the program crash in the most "loudly" way to alert the user can be a better option?....
    The OP is dealing with a Point Of Sale embedded W7 system. The "user" could be any person that walks up to the POS kiosk or a sales clerk. I don't think that the OP expects his app to crash, but why not make provisions for it?


    carwiz said:
    Careful how you set that up. You could send Windows into a close loop at shutdown.
    I understand what you are saying and why you said it - I've just been luck enough to work with tools that respect the OS shutdown notification. I don't even have to write code for prevent what you mentioned. If app1 is coded to restart app2 - app1 will not restart app2 if app1 has received an OS shutdown notice. The same goes for app2. Java might very well be different. Thanks for highlighting that danger.
      My Computer


  8. Posts : 7
    POS Ready Windows 7 Embedded Standard SP1 32 bit
    Thread Starter
       #8

    Thanks everyone for your suggestions and help - UsernameIssues hit the nail on the head, it is Point Of Sale embedded Windows 7. I was hoping to make it a service as we are using a program for remote access which can monitor and restart services. A second program looks like the way to go.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:55.
Find Us