| | |
| | | OnlineCheckThread thread = new OnlineCheckThread(monitor, checkPointUtil, time); |
| | | return thread.call(); // 假设 OnlineCheckThread 实现了 Callable 接口 |
| | | }, executorService) |
| | | .orTimeout(60, TimeUnit.SECONDS) |
| | | .orTimeout(120, TimeUnit.SECONDS) |
| | | .exceptionally(ex -> { |
| | | if (ex instanceof TimeoutException) { |
| | | log.error("任务执行超时:"+monitor.getIp()); |
| | |
| | | map = new HashMap<>(); |
| | | } |
| | | if (!monitor.getPingOnline()) { |
| | | try { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | } catch (IOException e) { |
| | | log.error("Ping异常{}",e.getMessage()); |
| | | } |
| | | reachable = checkPing(monitor, reachable); |
| | | if(!reachable) log.error("ping检测离线"+monitor.getIp()); |
| | | monitor.setPingOnline(reachable); |
| | | } |
| | |
| | | return monitor; |
| | | } |
| | | |
| | | private boolean checkPing(TMonitorResult monitor, boolean reachable) { |
| | | try { |
| | | int[] sleepTimes = {5000, 15000, 30000}; |
| | | for (int sleepTime : sleepTimes) { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | if (reachable) { |
| | | break; |
| | | } |
| | | Thread.sleep(sleepTime); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("Ping异常{}",e.getMessage()); |
| | | } |
| | | return reachable; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 监测点位在线 |