This commit is contained in:
caixiang 2022-08-09 14:16:03 +08:00
parent 3b1c667915
commit e373cd8e01

View File

@ -283,11 +283,11 @@ public enum S7Client {
} }
private void check_ping(){ private void check_ping(){
while (true){ ping_fail_check.execute(new Runnable() {
try {
ScheduledFuture<?> schedule = ping_fail_check.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
while (true){
try {
if(connections.size()!=coreSize){ if(connections.size()!=coreSize){
int c = coreSize-connections.size(); int c = coreSize-connections.size();
for(int z=0;z<c;z++){ for(int z=0;z<c;z++){
@ -301,22 +301,22 @@ public enum S7Client {
} }
} }
} Thread.sleep(10000);
}, 10000, TimeUnit.SECONDS);
Object o = schedule.get();
}catch (Exception e){ }catch (Exception e){
logger.info("( out catched ) host:"+host +" ;;(check_ping) "+"check connect.size 出现异常errMessage is : "+e.getMessage()+"现在进入下一次轮询"); logger.info(" ( outside check_ping catched ) host:"+host +" ;;(check_ping()) Thread.sleep 异常,异常原因:"+e.getMessage());
} }
} }
} }
});
}
//todo 当网络断开之后下面这个ping() 循环不生效 可能是read = connector.read( 出来是null但还是继续通过了也可能是 当连接全部断开后 getConnector(); 应该是取不到数据的也就会报null这个明天再看看 //todo 当网络断开之后下面这个ping() 循环不生效 可能是read = connector.read( 出来是null但还是继续通过了也可能是 当连接全部断开后 getConnector(); 应该是取不到数据的也就会报null这个明天再看看
private void ping(){ private void ping(){
while (true){ executor.execute(new Runnable() {
try {
ScheduledFuture<?> schedule = executor.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
while (true){
try {
for(int i=0;i<coreSize;i++){ for(int i=0;i<coreSize;i++){
S7Connector connector = getConnector(); S7Connector connector = getConnector();
try { try {
@ -328,6 +328,7 @@ public enum S7Client {
heartBeat.getByteOffset(), heartBeat.getByteOffset(),
heartBeat.getBitOffset(), heartBeat.getBitOffset(),
heartBeat.getType().getTransportSize()); heartBeat.getType().getTransportSize());
System.out.println("host:"+host +" ;; "+connector.hashCode()+" : ping"); System.out.println("host:"+host +" ;; "+connector.hashCode()+" : ping");
Thread.sleep(100); Thread.sleep(100);
}catch (Exception e){ }catch (Exception e){
@ -357,12 +358,13 @@ public enum S7Client {
} }
} }
} }
} Thread.sleep(30000);
}, 30000, TimeUnit.SECONDS);
Object o = schedule.get();
}catch (Exception e){ }catch (Exception e){
logger.info("( out catched ) host:"+host +" ;;(ping) "+"ping的时候 整体 出现异常errMessage is : "+e.getMessage()+"现在进入下一次轮询"); e.printStackTrace();
logger.info(" ( outside ping catched ) host:"+host +" ;;(ping) "+e.getMessage());
} }
} }
} }
});
}
} }