Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

asked on

Check status of a service

Please let me know how I can check if a particular service is running through java code on both a Windows machine and a Mac.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dshrenik

ASKER

Could you provide some sample code? Thanks!
For example, if I want to check if mysql is running, how do I figure that out?

This code is not working:

try {
        	int timeout = 2000;
        	InetAddress[] addresses = InetAddress.getAllByName("mysql");
        	for (InetAddress address : addresses) {
        		if (address.isReachable(timeout))
        			System.out.printf("%s is reachable%n", address);
        		else
        			System.out.printf("%s could not be contacted%n", address);
        	}
        } catch (Exception e) {
        	System.out.printf("Unknown host: %s%n", "www.java2s.com");
        }

Open in new window

To be reasonably sure: connect to the default mysql port. To be 100% sure, you'd have to become a (successful) mysql client
I had to use "mysql.net".

Thanks!
:)