使用自定义线程池

This commit is contained in:
Guoqs
2024-09-10 12:03:53 +08:00
parent 409307db85
commit 5e9beaf83a
13 changed files with 97 additions and 45 deletions

View File

@@ -10,6 +10,7 @@ import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.ykcCommond.IssueQRCodeCommand;
@@ -20,6 +21,7 @@ import com.jsowell.pile.service.YKCPushCommandService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
@@ -42,6 +44,9 @@ public class LoginRequestHandler extends AbstractYkcHandler {
private List<String> newProgramVersionList = Lists.newArrayList("c6-30");
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -200,7 +205,7 @@ public class LoginRequestHandler extends AbstractYkcHandler {
} catch (Exception e) {
e.printStackTrace();
}
});
}, executor);
// 异步发送对时指令
CompletableFuture.runAsync(() -> {
@@ -212,7 +217,7 @@ public class LoginRequestHandler extends AbstractYkcHandler {
// 对时
ProofreadTimeCommand command = ProofreadTimeCommand.builder().pileSn(pileSn).build();
ykcPushCommandService.pushProofreadTimeCommand(command);
});
}, executor);
// log.info("下面进行下发二维码 pileSn:{}, thread:{}", pileSn, Thread.currentThread().getName());
// 异步发送下发二维码指令
@@ -225,7 +230,7 @@ public class LoginRequestHandler extends AbstractYkcHandler {
// 下发二维码
IssueQRCodeCommand issueQRCodeCommand = IssueQRCodeCommand.builder().pileSn(pileSn).build();
ykcPushCommandService.pushIssueQRCodeCommand(issueQRCodeCommand);
});
}, executor);
if (StringUtils.equals("00", internetConnection)) {
CompletableFuture.runAsync(() -> {
@@ -236,7 +241,7 @@ public class LoginRequestHandler extends AbstractYkcHandler {
} catch (Exception e) {
log.error("更新充电桩sim卡信息失败pileSn:{}, iccid:{}", pileSn, iccid, e);
}
});
}, executor);
}
}
@@ -249,7 +254,7 @@ public class LoginRequestHandler extends AbstractYkcHandler {
} catch (Exception e) {
log.error("保存报文失败pileSn:{}", pileSn, e);
}
});
}, executor);
// 消息体
byte[] messageBody = Bytes.concat(pileSnByte, flag);

View File

@@ -7,6 +7,7 @@ import com.jsowell.common.enums.ykc.ChargingFailedReasonEnum;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.service.OrderBasicInfoService;
@@ -14,6 +15,7 @@ import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
@@ -35,6 +37,9 @@ public class RemoteStartChargingRequestHandler extends AbstractYkcHandler {
@Autowired
private CommonService commonService;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -121,7 +126,7 @@ public class RemoteStartChargingRequestHandler extends AbstractYkcHandler {
log.error("统一推送第三方平台订单信息error, ", e);
}
}
});
}, executor);
return null;
}
}

View File

@@ -15,6 +15,7 @@ import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileBasicInfo;
@@ -25,6 +26,7 @@ import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.Date;
@@ -46,6 +48,9 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_CODE.getBytes());
private final String oldVersionType = YKCUtils.frameType2Str(YKCFrameTypeCode.TRANSACTION_RECORDS_OLD_VERSION_CODE.getBytes());
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -647,7 +652,7 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
} catch (Exception e) {
log.error("绑定优惠券 error,", e);
}
});
}, executor);
// // 给车辆绑定优惠券
// try {
@@ -671,7 +676,7 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
log.error("推送第三方平台订单信息error, ", e);
e.printStackTrace();
}
});
}, executor);
// 异步推送第三方平台订单信息V2
CompletableFuture.runAsync(() -> {
@@ -681,7 +686,7 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
log.error("推送第三方平台订单信息error, ", e);
e.printStackTrace();
}
});
}, executor);
} else {
// 平台没有查到订单
orderBasicInfoService.saveAbnormalOrder(data);

View File

@@ -11,6 +11,7 @@ import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.service.OrderBasicInfoService;
@@ -19,6 +20,7 @@ import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.Date;
@@ -44,6 +46,9 @@ public class UploadRealTimeMonitorHandler extends AbstractYkcHandler {
YKCOperateFactory.register(oldVersionType, this);
}
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Autowired
private PileBasicInfoService pileBasicInfoService;
@@ -320,7 +325,7 @@ public class UploadRealTimeMonitorHandler extends AbstractYkcHandler {
} catch (Exception e) {
log.error("统一推送第三方平台实时数据 error,", e);
}
});
}, executor);
// 异步推送第三方平台实时数据V2
CompletableFuture.runAsync(() -> {
@@ -329,7 +334,7 @@ public class UploadRealTimeMonitorHandler extends AbstractYkcHandler {
} catch (Exception e) {
log.error("统一推送第三方平台实时数据V2 error, ", e);
}
});
}, executor);
return null;
}