多线程轮询调用
【多线程轮询调用】创建定时任务每隔一分钟调用一次:
SaticScheduleTask.java
package com.vimochina.vimo.util.Thread;
@Configuration//1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling// 2.开启定时任务
public class SaticScheduleTask{ /**
* @Description TODO 每个3600毫秒(1分钟) 调用一次
* @CreateBy shp
* @CreateTime 2020/6/17 10:47
* @param:
* @return void
*/
@Scheduled(cron = "0/3600 * * * * ?")
private void configureTasks() {ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(new ThreadTool.Thread1());
executor.submit(new ThreadTool.Thread2());
executor.submit(new ThreadTool.Thread3());
executor.submit(new ThreadTool.Thread4());
executor.submit(new ThreadTool.Thread5());
executor.shutdown();
}
}
创建个线程类
package com.vimochina.vimo.util.Thread;
public class ThreadTool {public static class Thread1 implements Runnable {@Override
public void run() {
System.out.println("我是线程1");
}}public static class Thread2 implements Runnable {@Override
public void run() {
System.out.println("我是线程2");
}}public static class Thread3 implements Runnable {@Override
public void run() {
System.out.println("我是线程3");
}}public static class Thread4 implements Runnable {@Override
public void run() {
System.out.println("我是线程4");
}}public static class Thread5 implements Runnable {@Override
public void run() {
System.out.println("我是线程5");
}}}
然后每隔一分钟就会调用多个线程,并且是安装线程一到线程五这种顺序
推荐阅读
- 放屁有这三个特征的,请注意啦!这说明你的身体毒素太多
- 爱就是希望你好好活着
- 昨夜小楼听风
- 知识
- 死结。
- 我从来不做坏事
- 烦恼和幸福
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- Linux下面如何查看tomcat已经使用多少线程
- 说得清,说不清