1 changed files with 49 additions and 0 deletions
@ -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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue