|
|
@ -1,5 +1,6 @@ |
|
|
package cn.chjyj.szwh.task; |
|
|
package cn.chjyj.szwh.task; |
|
|
|
|
|
|
|
|
|
|
|
import cn.chjyj.szwh.service.GoodsTaskService; |
|
|
import org.springframework.context.annotation.Bean; |
|
|
import org.springframework.context.annotation.Bean; |
|
|
import org.springframework.scheduling.TaskScheduler; |
|
|
import org.springframework.scheduling.TaskScheduler; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
@ -13,8 +14,18 @@ import java.time.LocalDateTime; |
|
|
* 多个定时任务启动 |
|
|
* 多个定时任务启动 |
|
|
*/ |
|
|
*/ |
|
|
@Component |
|
|
@Component |
|
|
@EnableScheduling |
|
|
//@EnableScheduling
|
|
|
public class SzwhScheduled { |
|
|
public class SzwhScheduled { |
|
|
|
|
|
private GoodsTaskService goodsTaskService; |
|
|
|
|
|
|
|
|
|
|
|
public GoodsTaskService getGoodsTaskService() { |
|
|
|
|
|
return goodsTaskService; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setGoodsTaskService(GoodsTaskService goodsTaskService) { |
|
|
|
|
|
this.goodsTaskService = goodsTaskService; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Bean |
|
|
@Bean |
|
|
public TaskScheduler taskScheduler(){ |
|
|
public TaskScheduler taskScheduler(){ |
|
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); |
|
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); |
|
|
@ -25,18 +36,20 @@ public class SzwhScheduled { |
|
|
/** |
|
|
/** |
|
|
* 查询查询撤销商品的信息 |
|
|
* 查询查询撤销商品的信息 |
|
|
*/ |
|
|
*/ |
|
|
@Scheduled(cron = "0/20 * * * * ?") |
|
|
//@Scheduled(cron = "0/20 * * * * ?")
|
|
|
public void queryRevocationGoods(){ |
|
|
public void queryRevocationGoods(){ |
|
|
String curName = Thread.currentThread().getName() ; |
|
|
String curName = Thread.currentThread().getName() ; |
|
|
System.out.println("当前时间:"+ LocalDateTime.now()+" 任务queryRevocationGoods对应的线程名: "+curName); |
|
|
System.out.println("当前时间:"+ LocalDateTime.now()+" 任务queryRevocationGoods对应的线程名: "+curName); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
goodsTaskService.getRevocationGoods(); |
|
|
Thread.sleep(1000); |
|
|
Thread.sleep(1000); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/5 * * * * ?") |
|
|
//@Scheduled(cron = "0/5 * * * * ?")
|
|
|
public void execute2(){ |
|
|
public void execute2(){ |
|
|
String curName = Thread.currentThread().getName() ; |
|
|
String curName = Thread.currentThread().getName() ; |
|
|
System.out.println("当前时间:"+LocalDateTime.now()+" 任务execute2对应的线程名: "+curName); |
|
|
System.out.println("当前时间:"+LocalDateTime.now()+" 任务execute2对应的线程名: "+curName); |
|
|
|