Browse Source

修复定时任务不执行的问题

master
wxc 2 months ago
parent
commit
85ca166b03
  1. 35
      mailbox-outer/src/main/java/com/biutag/outer/config/SchedulerConfig.java
  2. 24
      mailbox-outer/src/main/java/com/biutag/outer/job/Job.java

35
mailbox-outer/src/main/java/com/biutag/outer/config/SchedulerConfig.java

@ -0,0 +1,35 @@
package com.biutag.outer.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author wxc
* @date 2025/9/22
*/
@Configuration
@EnableScheduling
public class SchedulerConfig {
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
// 设置线程池大小
scheduler.setPoolSize(10);
// 设置线程名前缀
scheduler.setThreadNamePrefix("scheduled-task-");
// 设置线程池关闭时等待所有任务完成
scheduler.setWaitForTasksToCompleteOnShutdown(true);
// 设置等待终止时间(单位:秒)
scheduler.setAwaitTerminationSeconds(60);
// 设置拒绝策略
scheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化线程池
scheduler.initialize();
return scheduler;
}
}

24
mailbox-outer/src/main/java/com/biutag/outer/job/Job.java

@ -72,7 +72,9 @@ public class Job {
.maximumSize(1000)
.build();
// 60s
/**
* 每60s执行一次1分钟
*/
@Scheduled(fixedRate = 60000)
public void pushMailData() {
log.info("推送信件数据-----------------------------");
@ -133,9 +135,9 @@ public class Job {
}
/**
* 推送信件评价(网络) 60 s
* 推送信件评价(网络) 10分钟
*/
@Scheduled(fixedRate = 60000)
// @Scheduled(cron = "0 */10 * * * ?")
public void pushMailEvaluate() {
log.info("推送信件评价(网络)-----------------------------");
List<Mail> mails = mailMapper.listByMailEvaluateEtl();
@ -166,9 +168,9 @@ public class Job {
}
/**
* 推送信件评价(短信) 60 s
* 推送信件评价(短信) 10分钟
*/
@Scheduled(fixedRate = 60000)
@Scheduled(cron = "0 */10 * * * ?")
public void pushMailSmsEvaluate() {
log.info("推送信件评价(短信)-----------------------------");
List<SmsSend> mails = mailMapper.listByMailSmsEvaluateEtl();
@ -202,7 +204,7 @@ public class Job {
}
/**
* 发送短信
* 发送短信 60s
*/
@Scheduled(fixedRate = 60000)
public void sendSms() {
@ -245,9 +247,9 @@ public class Job {
}
/**
* 更新信件状态 60s
* 更新信件状态 10分钟
*/
@Scheduled(fixedRate = 60000)
@Scheduled(cron = "0 */10 * * * ?")
public void updateMailState() {
List<Mail> mails = mailMapper.listByMailState();
log.info("未获取信件状态的数量为:{}", mails.size());
@ -280,7 +282,7 @@ public class Job {
/**
* 黑名单 10分钟 更新一次
*/
@Scheduled(fixedRate = 600000)
@Scheduled(cron = "0 */10 * * * ?")
public void balcklist() {
long timestamp = new Date().getTime();
HttpResponse httpResponse = HttpUtil.createRequest(Method.GET, mailboxUrl + "blacklist")
@ -328,9 +330,9 @@ public class Job {
}
/**
* 推送12345信箱服务
* 推送12345信箱服务 60s
*/
@Scheduled(cron = "0 0 1 * * *")
@Scheduled(fixedRate = 60000)
public void push12345() {
log.info("推送12345信箱服务-----------------------------");
try {

Loading…
Cancel
Save