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

cr0ck3t

New member
Local time
7:04 AM
Messages
7
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
J2/K755
OS
POS Ready Windows 7 Embedded Standard SP1 32 bit
CPU
Intel Atom D2550
Memory
2 GB
Graphics Card(s)
Intel Graphics Media Accelerator 3600 Series, PCI GDIHOOK5
Hard Drives
30 GB
Browser
Chrome
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

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 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.

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:

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
J2/K755
OS
POS Ready Windows 7 Embedded Standard SP1 32 bit
CPU
Intel Atom D2550
Memory
2 GB
Graphics Card(s)
Intel Graphics Media Accelerator 3600 Series, PCI GDIHOOK5
Hard Drives
30 GB
Browser
Chrome
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

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
Careful how you set that up. You could send Windows into a close loop at shutdown.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Built 2/11/2011
OS
Windows 7 Pro-x64
CPU
i7-2600 3.4GHz - 3.8GHz Turbo
Motherboard
Intel DH67BL-B3
Memory
8Gb - 2x4GB, Muskin 991770 PC3-1333
Graphics Card(s)
Integrated Intel HD 2000
Sound Card
Integrated Intel 10.1 HD, RealTek ALC892
Monitor(s) Displays
Asus LCD VH222H, Haier HL24XSL2a
Screen Resolution
1920x1080, 1920x1080
Hard Drives
Crucial SSD C300-128Gb,
Western Digital WD5002AALX - 500Gb,
Western Digital WD7501AALS - 750Gb
PSU
Seasonic 650W 80+ Gold Modular
Case
Rosewill Defender
Cooling
Stock CPU, Four 120mm case fans, PCH fan added
Keyboard
Logitech EX100 Y-RBH94 Wireless
Mouse
Logitech EX100 M-RCE95 Wireless
Internet Speed
3.0/1.5 Mbs
Antivirus
Microsoft Security Essentials
Browser
Microsoft Internet Explorer 11
Other Info
Antec Veris Premier-Multimedia IR Station,
Cyber Accoustics-3602 Speakers,
AFT XM-5U Card Reader,
Hauppauge TV-HVR-2250,
Sony LX300 USB Turntable
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?


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

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
J2/K755
OS
POS Ready Windows 7 Embedded Standard SP1 32 bit
CPU
Intel Atom D2550
Memory
2 GB
Graphics Card(s)
Intel Graphics Media Accelerator 3600 Series, PCI GDIHOOK5
Hard Drives
30 GB
Browser
Chrome
Back
Top