需要添加http依赖:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
当系统故障无法及时发现时就需要有这么个服务,定时访问url,无法访问发送邮件,当收到邮件的时候就可以及时处理了
package com.epson.esl.rms;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TestUrl {
public static void main(String[] args) {
timer1();
}
public static void timer1() {
Timer nTimer = new Timer();
nTimer.schedule(new TimerTask() {
@Override
public void run() {
testUrlWithTimeOut("http://127.0.0.1:8888", 20000); //超时时间 20秒
}
},0, 300000); // 0代表立即执行一次task,然后每隔300秒执行一次task
}
public static void testUrlWithTimeOut(String urlString, int timeOutMillSeconds) {
URL url;
try {
url = new U