From c1bf2cbd6a26a492e766e12dfbd8e284bde44831 Mon Sep 17 00:00:00 2001 From: xyiege Date: Mon, 26 Sep 2022 10:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/chjyj/szwh/task/SzwhScheduled.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/cn/chjyj/szwh/task/SzwhScheduled.java diff --git a/src/main/java/cn/chjyj/szwh/task/SzwhScheduled.java b/src/main/java/cn/chjyj/szwh/task/SzwhScheduled.java new file mode 100644 index 0000000..18eb19c --- /dev/null +++ b/src/main/java/cn/chjyj/szwh/task/SzwhScheduled.java @@ -0,0 +1,49 @@ +package cn.chjyj.szwh.task; + +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +/** + * 多个定时任务启动 + */ +@Component +@EnableScheduling +public class SzwhScheduled { + @Bean + public TaskScheduler taskScheduler(){ + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + taskScheduler.setPoolSize(20); + return taskScheduler; + } + + /** + * 查询查询撤销商品的信息 + */ + @Scheduled(cron = "0/20 * * * * ?") + public void queryRevocationGoods(){ + String curName = Thread.currentThread().getName() ; + System.out.println("当前时间:"+ LocalDateTime.now()+" 任务queryRevocationGoods对应的线程名: "+curName); + try { + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Scheduled(cron = "0/5 * * * * ?") + public void execute2(){ + String curName = Thread.currentThread().getName() ; + System.out.println("当前时间:"+LocalDateTime.now()+" 任务execute2对应的线程名: "+curName); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +}