コード例 #1
0
  public static void resetWeblogic() throws IOException {
    if (bool) {
      bool = false; // 服务停止后等再次启动能够连接后才重新检测
      // ex.printStackTrace();
      // Runtime.getRuntime().exec("cmd /k start
      // E:\\bea\\user_projects\\domains\\base_domain\\bin\\stopWebLogic.cmd");
      // //java调用bat文件
      //			System.out.println(bartDateFormat.format(data)+" 服务已经停止!");
      //			System.out.println(bartDateFormat.format(data)+" サービスが停止されています!");
      //			System.out.println(bartDateFormat.format(data)+" Service has been stopped!");
      explainaddln(bartDateFormat.format(date) + " 服务已经停止!");
      explainaddln(bartDateFormat.format(date) + " サービスが停止されています!");
      explainaddln(bartDateFormat.format(date) + " Service has been stopped!");
      status = 3;
      if (cmdbool == 1) {
        Runtime.getRuntime().exec(cmdstop); // java调用bat文件
        explainaddln(cmdstop);
        try {
          Thread.currentThread().sleep(5 * 1000); // 停止服务后延时5秒后再启动服务
        } catch (Exception e) {
          // TODO: handle exception
        }
      }
      //			System.out.println(cmdstart);
      explainaddln(cmdstart);
      Runtime.getRuntime().exec(cmdstart); // java调用bat文件

    } else {
      date = new Date();
      String string = bartDateFormat.format(date) + " Maximo监控:服务正在启动!";
      if (status == 1) {
        explaindelln();
      } else {
        string = "\n" + string;
      }
      zenkai = shoukaiseki.math.PrintPercent.length(string);
      //			System.out.print(string);
      explainaddln(string);
      status = 1;
    }
  }
コード例 #2
0
  public static void method1() throws Exception {
    // 文件保存路径
    URL url = null;
    HttpURLConnection httpConn = null;
    InputStream in = null;

    try {
      url = new URL(theurl);
      httpConn = (HttpURLConnection) url.openConnection();
      HttpURLConnection.setFollowRedirects(true);
      httpConn.setRequestMethod("GET");
      httpConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");

      // logger.info(httpConn.getResponseMessage());
      in = httpConn.getInputStream();
      // 将URL读入的网页信息转换为String输出
      urlstring = convertStreamToString(in);
      urlstring = new String(urlstring.getBytes(), "UTF8");
      date = new Date();
      if (urlstring.indexOf(logo) < 0) {
        //				 System.out.println(urlstring);
        //				 System.out.println("logo="+logo);
        //				 System.out.println("Maximo服务异常,无法得到正确的页面信息!");
        explainaddln("Maximo服务异常,无法得到正确的页面信息!");
        status = 88;
        throw new MalformedURLException();
      }
      String string = bartDateFormat.format(date) + " Maximo服务运行正常!";
      if (status == 2) {
        explaindelln();

        cal.setTime(rundate);
        long timeOne = cal.getTimeInMillis();
        cal.setTime(date); // 将日历翻到1945年八月十五日,7表示八月

        long timeTwo = cal.getTimeInMillis();
        long daysapart = (timeTwo - timeOne) / (1000 * 60 * 60 * 24); // 二者时间相隔天数,第几天要加1
        long hoursapart =
            (timeTwo - timeOne) % (1000 * 60 * 60 * 24) / (1000 * 60 * 60); // 二者时间相隔天数,第几天要加1
        long minutesapart = (timeTwo - timeOne) % (1000 * 60 * 60) / (1000 * 60); // 二者时间相隔天数,第几天要加1
        long secondsapart = (timeTwo - timeOne) % (1000 * 60) / (1000); // 二者时间相隔天数,第几天要加1
        string =
            string
                + "\t正常运行时间为"
                + daysapart
                + "天"
                + hoursapart
                + "时"
                + minutesapart
                + "分"
                + secondsapart
                + "秒";
      } else {
        string = "\n" + string;
        rundate = new Date(); // 从此刻开始正常运行		cal.set(2011,0,1,21,12,11);//设置今年的1月1日
      }

      zenkai = shoukaiseki.math.PrintPercent.length(string);
      explainaddln(string);
      status = 2;
      bool = true; // 服务停止后等再次启动能够连接后才重新检测

    } catch (MalformedURLException e) {
      resetWeblogic(); // 重启服务
      // e.printStackTrace();
    } catch (IOException e) {
      resetWeblogic(); // 重启服务
      // e.printStackTrace();
    } finally {
      try {
        in.close();
        httpConn.disconnect();

      } catch (Exception ex) {
        resetWeblogic(); // 重启服务
      }
    }
  }