Authored by jack

增加redis 重连

... ... @@ -39,6 +39,11 @@ public class RedisTask extends Task {
this.tUrl = tUrl;
sureConnect();
}
private void connect() {
try {
client = new Jedis(this.getIp(), this.getPort(), 5 * 1000);
... ... @@ -50,7 +55,28 @@ public class RedisTask extends Task {
client = null;
}
}
private void sureConnect() {
DEBUG.info("start to connect to redis {},time {}", super.url, System.currentTimeMillis());
connect();
//等待两秒重连
try {
Thread.sleep(2 * 1000);
} catch (InterruptedException e) {
DEBUG.error("Failed to wait for reconnect to redis {}", super.url);
}
if (null == client || !client.isConnected()) {
connect();
}
DEBUG.info("End to connect to redis {},time {}", super.url, System.currentTimeMillis());
}
... ...
... ... @@ -24,7 +24,7 @@ public class Task implements Callable {
public static final Logger DEBUG = LoggerFactory.getLogger(Task.class);
@Getter
private String url;
protected String url;
@Getter
private String ip;
... ... @@ -32,7 +32,6 @@ public class Task implements Callable {
@Getter
private int port;
@Getter
private AlarmMsgService alarmMsgService;
... ...