Check if Glassfish DAS is running programmatically

后端 未结 3 867
南笙
南笙 2021-01-16 06:52

How to check if Glassfish DAS is running programmatically even if it is deployed on local machine or remote machine?

Using Java6

相关标签:
3条回答
  • 2021-01-16 07:13

    I have found a way to check if DAS is up other than Linux script. With this way it does not matter if both my application and DAS are at same machine or each installed different machine.

    public static boolean isUrlReachable(String host) {
      String URLName="http://"+host+":4848";
      boolean isUp = false;
      try {
         HttpURLConnection.setFollowRedirects(false);
         HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
         con.setRequestMethod("GET");
         isUp = (con.getResponseCode() == HttpURLConnection.HTTP_OK);
         con.disconnect();
      }
      catch (Exception e) {
         return isUp;
      }
    
      return isUp;
    

    }

    0 讨论(0)
  • 2021-01-16 07:24

    This is how you would normally check that glassfish is up and running:

    enter image description here

    But since you want to run it programmaticaly, what you can do is create an script and execute the script from the code with java.

    try{
    Runtime.getRuntime().exec("Path to my script");
    } 
    catch(IOException e) {
    System.out.println("exception");
    }
    

    If you are in linux, you could also create an script to grep for the glassfish process.

    0 讨论(0)
  • 2021-01-16 07:27

    You can use socket to check if your connection up or not :

    i use this way this work with me:

    private boolean checkConnection(String host, int port) {
        try {
            Socket socket = new Socket(host, port);
            socket.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    

    If the socket is created then the connection is up, else the connection is down.

    0 讨论(0)
提交回复
热议问题