Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

29 Nov 2013   #1
cr0ck3t

POS Ready Windows 7 Embedded Standard SP1 32 bit
 
 
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 System SpecsSystem Spec
.
30 Nov 2013   #2
UsernameIssues

W7 Pro SP1 64bit
 
 

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 System SpecsSystem Spec
30 Nov 2013   #3
cr0ck3t

POS Ready Windows 7 Embedded Standard SP1 32 bit
 
 

Quote   Quote: Originally Posted by UsernameIssues View Post
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.
My System SpecsSystem Spec
.

30 Nov 2013   #4
UsernameIssues

W7 Pro SP1 64bit
 
 

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 System SpecsSystem Spec
30 Nov 2013   #5
Alejandro85

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
30 Nov 2013   #6
carwiz

Windows 7 Pro-x64
 
 

Careful how you set that up. You could send Windows into a close loop at shutdown.
My System SpecsSystem Spec
30 Nov 2013   #7
UsernameIssues

W7 Pro SP1 64bit
 
 

Quote   Quote: Originally Posted by Alejandro85 View Post
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?


Quote   Quote: Originally Posted by carwiz View Post
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 System SpecsSystem Spec
03 Dec 2013   #8
cr0ck3t

POS Ready Windows 7 Embedded Standard SP1 32 bit
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Java Problem running IE9 in Win 7 64 bit
Does anyone know how I can get rid of this error? I have scanned the web for so long for an answer that I finally realized I don't even understand the difference between Sun Java and Oracle Java nor do I know how to get rid of either and start over. Any help offered will be greatly appreciated....
Browsers & Mail
BSOD random times, while opening any application.
My screen keeps distorting and freezing whenever I log on for 2 mins or 2 hours. I keep trying to play SWOTR and my wife plays the Sims. I bought a new power supply recently because it went bad. Now all the sudden this has started. Windows Enterprise 7 x64 Original IU ware enterprise install. ...
BSOD Help and Support
Java Application and system tray
Hi All, we have a strange problem with System tray icon and windows seven. The application need to create a system tray icon and add a message. On XP and Vista the application work fine. SEVEN: If the application run by console and the owner of java process is user logged in the system tray...
Software
Nested Application Folders Directory (many times)
I re-installed Windows 7 so that I could run a 64bit version instead of the 32bit version. When I searched for old user files in Windows.old so that I could restore old favorites and documents, I found that All Users\Application Data had Application Data nested underneath it and that repeated many...
General Discussion
Java application wont install win7
I have Jre6 installed already. When I double click on the jar executable , the program stars. The default program location is C:\program files\Evodatamanager. When tries to install I get the error message : "Cannot write to this folder chose another" I tried to install as administrator but...
Software
Unable to access any JAVA application
My computer was complete okay a week ago and i have didn't touch anything to change either firewall setting or antivirus. At least for a couple of days now i have this weird experience unable to access any application or websites that run using JAVA. Any java website especially this:...
System Security


Our Sites

Site Links

About Us

Find 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 03:26.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App