6 changed files with 59 additions and 99 deletions
@ -1,62 +0,0 @@ |
|||||
package cn.chjyj.szwh.task; |
|
||||
|
|
||||
import cn.chjyj.szwh.service.GoodsTaskService; |
|
||||
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 { |
|
||||
private GoodsTaskService goodsTaskService; |
|
||||
|
|
||||
public GoodsTaskService getGoodsTaskService() { |
|
||||
return goodsTaskService; |
|
||||
} |
|
||||
|
|
||||
public void setGoodsTaskService(GoodsTaskService goodsTaskService) { |
|
||||
this.goodsTaskService = goodsTaskService; |
|
||||
} |
|
||||
|
|
||||
@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 { |
|
||||
goodsTaskService.getRevocationGoods(); |
|
||||
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(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,22 @@ |
|||||
|
package cn.chjyj.szwh.service; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
|
||||
|
import static org.junit.Assert.*; |
||||
|
|
||||
|
@SpringBootTest |
||||
|
@RunWith(SpringJUnit4ClassRunner.class) |
||||
|
public class OrderTaskServiceTest { |
||||
|
@Autowired |
||||
|
private OrderTaskService orderTaskService; |
||||
|
|
||||
|
@Test |
||||
|
public void closeOrderTimeout() { |
||||
|
System.out.println("关闭订单"); |
||||
|
orderTaskService.closeOrderTimeout(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue