优化代码

main
gaoshuguang 1 year ago
parent 4e81c6d0d9
commit 5e658e1ad3

@ -234,6 +234,7 @@ public class Constant {
public static final String STR_TO_DATE_FORMAT = "DATE_FORMAT(MMMMM,'%Y-%m-%d') = 'NNNNN'"; public static final String STR_TO_DATE_FORMAT = "DATE_FORMAT(MMMMM,'%Y-%m-%d') = 'NNNNN'";
public static final String SELECT_ALL_ROAD_MIN_FEE_TABLE = "SELECT VERSION,VALIDTIME,ENPROV,ENID,EXPROV,EXID,FEEINFO FROM ALLROADMINFEE_TABLE"; public static final String SELECT_ALL_ROAD_MIN_FEE_TABLE = "SELECT VERSION,VALIDTIME,ENPROV,ENID,EXPROV,EXID,FEEINFO FROM ALLROADMINFEE_TABLE";
public static final String SQLITE_PRE = "jdbc:sqlite:"; public static final String SQLITE_PRE = "jdbc:sqlite:";
public static final String SEND_FZX_HANG_TABLE_URL = "http://10.15.110.216:9020/SendCallBack/paramDownload/sendFZXHangTable";
} }

@ -18,6 +18,30 @@ import java.util.concurrent.ThreadPoolExecutor;
@EnableScheduling // 开启定时任务 @EnableScheduling // 开启定时任务
@EnableAsync //开启对异步定时任务的支持 @EnableAsync //开启对异步定时任务的支持
public class TaskThreadPoolConfig { public class TaskThreadPoolConfig {
@Bean("threadPoolSendFZXHangTable") // bean的名称默认为首字母小写的方法名
public Executor threadPoolSendFZXHangTable() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//线程前缀名
executor.setThreadNamePrefix("timeTaskSendFZXHangTable-thread-");
//最大线程数
executor.setMaxPoolSize(1);
//核心线程数
executor.setCorePoolSize(1);
//任务队列的大小
executor.setQueueCapacity(5);
//这种策略下,因为线程池已经无法接纳新的任务了,那么谁提交的这个任务,谁就去跑这个业务;
//
//比如,主线程向线程池提交了一个任务,线程池已经不能接纳这个任务了,那么此时就会让这个提交任务的主线程去执行这个任务;
//
//这种策略有两点好处1这种策略避免了业务损失2可以让任务提交的速度降低下来比如主线程提交的任务被打回来后主线程就必须执行完这个被打回来的任务后才能够向线程池提交下一个任务而这就相当于给了线程池一个缓冲的时间
//executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//这种策略,会默默的把新来的这个任务给丢弃;我们不会得到通知;
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
//线程初始化
executor.initialize();
return executor;
}
@Bean("threadPoolIntoDatabase241") // bean的名称默认为首字母小写的方法名 @Bean("threadPoolIntoDatabase241") // bean的名称默认为首字母小写的方法名
public Executor threadPoolIntoDatabase241() { public Executor threadPoolIntoDatabase241() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

@ -95,6 +95,29 @@ public class TimeTaskInfo {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-]定时ETC参数(最小费额)下载及处理服务执行完成,耗时毫秒=" + (end - start), "TimeTaskInfo-timeTaskMinFee"); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-]定时ETC参数(最小费额)下载及处理服务执行完成,耗时毫秒=" + (end - start), "TimeTaskInfo-timeTaskMinFee");
} }
/**
*
*
* @author shuguang
* @date 2023-07-24 10:37
*/
@Async("threadPoolSendFZXHangTable")
@Scheduled(cron = "${time.corn10}")
public void timeTaskSendFZXHangTable() {
String uuid = UuidUtil.getUuid();
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-定时调用自动下发接口下发分中心省内黑名单表,当前时间=" + LocalDateTime.now(), "TimeTaskInfo-timeTaskSendFZXHangTable");
long start = System.currentTimeMillis();
boolean b = callSendOutInterfaceService.SendFZXHangTableInterface(uuid);
long end = System.currentTimeMillis();
if (b) {
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-]定时调用自动下发接口下发分中心省内黑名单表执行完成,耗时毫秒=" + (end - start), "TimeTaskInfo-timeTaskSendFZXHangTable");
} else {
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-]当前程序不调用自动下发接口下发分中心省内黑名单表,耗时毫秒=" + (end - start), "TimeTaskInfo-timeTaskSendFZXHangTable");
}
}
/** /**
* *
* *

@ -51,6 +51,11 @@ public class LogUtil {
String fileName = f.format(new Date()) + "_InsertDB"; String fileName = f.format(new Date()) + "_InsertDB";
WriteLog(fileName, msg, disStr); WriteLog(fileName, msg, disStr);
} }
public static void WriteLog_SendFZXHangTableInterface(String msg, String disStr) {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH");
String fileName = f.format(new Date()) + "_SendFZXHangTableInterface";
WriteLog(fileName, msg, disStr);
}
public static void WriteLog_CallDisInterface(String msg, String disStr) { public static void WriteLog_CallDisInterface(String msg, String disStr) {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH"); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH");
String fileName = f.format(new Date()) + "_CallDisInterface"; String fileName = f.format(new Date()) + "_CallDisInterface";

@ -6,6 +6,13 @@ package com.nm.gsgl.service;
* @description: * @description:
*/ */
public interface CallSendOutInterfaceService { public interface CallSendOutInterfaceService {
/**
*hang_table_collectHANG_TABLE
* @author shuguang
* @date 2024-11-15 10:18
* @param uuid uuid
*/
boolean SendFZXHangTableInterface(String uuid);
/** /**
* *
* @author shuguang * @author shuguang

@ -1,7 +1,9 @@
package com.nm.gsgl.service.impl; package com.nm.gsgl.service.impl;
import com.nm.gsgl.common.Constant;
import com.nm.gsgl.common.utils.CloseableHttpClientUtils; import com.nm.gsgl.common.utils.CloseableHttpClientUtils;
import com.nm.gsgl.common.utils.LogUtil; import com.nm.gsgl.common.utils.LogUtil;
import com.nm.gsgl.common.utils.PropertiesUtil;
import com.nm.gsgl.entity.intermediary.AppAliveStatus; import com.nm.gsgl.entity.intermediary.AppAliveStatus;
import com.nm.gsgl.mapper.AppAliveStatusMapper; import com.nm.gsgl.mapper.AppAliveStatusMapper;
import com.nm.gsgl.service.CallSendOutInterfaceService; import com.nm.gsgl.service.CallSendOutInterfaceService;
@ -25,6 +27,32 @@ public class CallSendOutInterfaceServiceImpl implements CallSendOutInterfaceServ
private AppAliveStatusMapper appAliveStatusMapper; private AppAliveStatusMapper appAliveStatusMapper;
//public static Logger log = LoggerFactory.getLogger("CallDisInterface"); //public static Logger log = LoggerFactory.getLogger("CallDisInterface");
/**
* hang_table_collectHANG_TABLE
*
* @param uuid uuid
* @author shuguang
* @date 2024-11-15 10:18
*/
@Override
public boolean SendFZXHangTableInterface(String uuid) {
//双机方案
//获取本机的机器ID,本机的机器ID 1-主机2-备用机
int mId = Integer.parseInt(machineId);
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-获取当前机器的id为" + mId, "CallSendOutInterfaceServiceImpl-SendFZXHangTableInterface");
AppAliveStatus appAliveStatus = appAliveStatusMapper.selectById(1);
int aLiveId = appAliveStatus.getALiveId();
if (mId == aLiveId) {
String sendFZXHangTableUrl = PropertiesUtil.getValue("SendFZXHangTableUrl") == null ? Constant.SEND_FZX_HANG_TABLE_URL : PropertiesUtil.getValue("SendFZXHangTableUrl");
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-开始调用自动下发接口省内黑名单表直连分中心对相应片区的hang_table_collect表内数据直连分中心数据库完成对表HANG_TABLE的先删后插" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl-SendFZXHangTableInterface");
CloseableHttpClientUtils.doGet(sendFZXHangTableUrl, null, null, 600000);
LogUtil.WriteLog_SendFZXHangTableInterface("[uuid:" + uuid + "]-调用自动下发接口省内黑名单表直连分中心对相应片区的hang_table_collect表内数据直连分中心数据库完成对表HANG_TABLE的先删后插完成" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl-SendFZXHangTableInterface");
return true;
} else {
return false;
}
}
/** /**
* *
* *
@ -38,15 +66,15 @@ public class CallSendOutInterfaceServiceImpl implements CallSendOutInterfaceServ
//获取本机的机器ID,本机的机器ID 1-主机2-备用机 //获取本机的机器ID,本机的机器ID 1-主机2-备用机
int mId = Integer.parseInt(machineId); int mId = Integer.parseInt(machineId);
//log.info("[uuid:{}]获取当前机器的id为{}", uuid, mId); //log.info("[uuid:{}]获取当前机器的id为{}", uuid, mId);
LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-获取当前机器的id为" + mId, "CallSendOutInterfaceServiceImpl"); LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-获取当前机器的id为" + mId, "CallSendOutInterfaceServiceImpl-callSendOutInterface");
AppAliveStatus appAliveStatus = appAliveStatusMapper.selectById(1); AppAliveStatus appAliveStatus = appAliveStatusMapper.selectById(1);
int aLiveId = appAliveStatus.getALiveId(); int aLiveId = appAliveStatus.getALiveId();
if (mId == aLiveId) { if (mId == aLiveId) {
//log.info("[uuid:{}]开始调用自动下发程序接口-{}进行下发", uuid, sendOutInterfaceUrl); //log.info("[uuid:{}]开始调用自动下发程序接口-{}进行下发", uuid, sendOutInterfaceUrl);
LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-开始调用自动下发程序接口进行下发" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl"); LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-开始调用自动下发程序接口进行下发" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl-callSendOutInterface");
CloseableHttpClientUtils.doGet(sendOutInterfaceUrl, null, null, 600000); CloseableHttpClientUtils.doGet(sendOutInterfaceUrl, null, null, 600000);
//log.info("[uuid:{}]调用自动下发程序接口-{}进行下发完成", uuid, sendOutInterfaceUrl); //log.info("[uuid:{}]调用自动下发程序接口-{}进行下发完成", uuid, sendOutInterfaceUrl);
LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-调用自动下发程序接口下发完成" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl"); LogUtil.WriteLog_CallDisInterface("[uuid:" + uuid + "]-调用自动下发程序接口下发完成" + sendOutInterfaceUrl, "CallSendOutInterfaceServiceImpl-callSendOutInterface");
return true; return true;
} else { } else {
return false; return false;

@ -21,3 +21,5 @@ time.corn7= 0 0/5 * * * ?
time.corn8= 0 0/5 * * * ? time.corn8= 0 0/5 * * * ?
#每5分钟执行一次 #每5分钟执行一次
time.corn9= 0 0/5 * * * ? time.corn9= 0 0/5 * * * ?
#每一小时执行一次
time.corn10= 0 0 0/1 * * ?

Loading…
Cancel
Save