无限重连

cangzhou-yancao
LAPTOP-S9HJSOEB\昊天 3 years ago
parent 71de5ccd65
commit 2b149efd64

@ -82,6 +82,8 @@ public class ConfigProperties {
public static class KSEC{ public static class KSEC{
private String ip; private String ip;
private Integer port; private Integer port;
private Integer reconnectNum = 10;
private Integer reconnectInterval = 10;
} }
@Data @Data

@ -67,13 +67,18 @@ public class KsecNettyClient {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
while (num < RECONNECT_NUM && !isConnected) { while ((ksec.getReconnectNum() == -1 || num < ksec.getReconnectNum() ) && !isConnected) {
try { try {
createClient(ksec); createClient(ksec);
} catch (Exception e) { } catch (Exception e) {
//没连上 继续 //没连上 继续
log.error("reconnect error num:{}", num); log.error("reconnect error num:{}", num);
num++; num++;
try {
Thread.sleep(ksec.getReconnectInterval()*1000);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
continue; continue;
} }
isConnected = true; isConnected = true;

Loading…
Cancel
Save