int pageSize = 10000;
int totalCount = doctorDAO.selectDatasByMapCount2(jsonArray, false, null);
int m = totalCount % pageSize;
int pageCount = m == 0 ? (totalCount / pageSize) : (totalCount / pageSize + 1); List<DoctorDO> resultList = new ArrayList<>();
BlockingQueue<Future<List<DoctorDO>>> queue = new LinkedBlockingQueue<>(); for (int i = 0; i < pageCount; i++) {
Thread.sleep(0);
Future<List<DoctorDO>> future;
future = queryDatas(jsonArray, i * pageSize, pageSize);
queue.add(future);
} int queueSize = queue.size();
logger.debug("queue size:" + queueSize);
for (int i = 0; i < queueSize; i++) {
List<DoctorDO> subAttendList = queue.take().get();
if (!CollectionUtils.isEmpty(subAttendList)) {
resultList.addAll(subAttendList);
}
}
     @Async
public Future<List<DoctorDO>> queryDatas(JSONArray jsonArray, int start, int size) {
List<DoctorDO> subAttendList = doctorDAO.selectDatasByMap2(start, size, jsonArray, true, null);
logger.info("完成任务");
return new AsyncResult<>(subAttendList);
}
 import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.lang.reflect.Method;
import java.util.concurrent.Executor; /**
* 多线程配置类
*/
@Configuration
@EnableAsync
public class ThreadConfig implements AsyncConfigurer {
private static Logger logger = LoggerFactory.getLogger(ThreadConfig.class); /**
* The {@link Executor} instance to be used when processing async
* method invocations.
*/
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(15);
executor.setMaxPoolSize(25);
executor.setQueueCapacity(25);
executor.initialize();
return executor;
} /**
* The {@link AsyncUncaughtExceptionHandler} instance to be used
* when an exception is thrown during an asynchronous method execution
* with {@code void} return type.
*/
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SpringAsyncExceptionHandler();
} class SpringAsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... obj) {
throwable.printStackTrace();
}
} public static void main(String[] args) {
logger.info("123");
logger.info("123");
logger.info("123");
}
}

springboot 多线程的使用的更多相关文章

  1. springboot 多线程执行

    一.springboot开线程执行异步任务 1.Spring通过任务执行器TaskExecutor,来实现多线程和并发编程,使用ThreadPoolTaskExecutor可实现一个基于线程池的Tas ...

  2. SpringBoot 多线程

    Spring通过任务执行器(TaskExecutor)来实现多线程和并发编程.使用ThreadPoolTaskExecutor可实现一个基于线程池的TaskExecutor.而实际开发中任务一般是非阻 ...

  3. spring-boot 多线程

    //配置类 package test; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import ...

  4. 玩转SpringBoot之定时任务@Scheduled线程池配置

    序言 对于定时任务,在SpringBoot中只需要使用@Scheduled 这个注解就能够满足需求,它的出现也给我们带了很大的方便,我们只要加上该注解,并且根据需求设置好就可以使用定时任务了. 但是, ...

  5. springboot下多线程开发注意事项

    基于springboot的多线程程序开发过程中,由于本身也需要注入spring容器进行管理,才能发挥springboot的优势.所以这篇文字主要用来记录开发中两者结合时需要注意的一些事项. 第一步我们 ...

  6. 关于java基础、多线程、JavaWeb基础、数据库、SSM、Springboot技术汇总

    作者 : Stanley 罗昊 本人自行总结,纯手打,有疑问请在评论区留言 [转载请注明出处和署名,谢谢!] 一.java基础 1.多态有哪些体现形式? 重写.重载 2. Overriding的是什么 ...

  7. 转载-SpringBoot结合线程池解决多线程问题实录;以及自己的总结

    原文地址:https://blog.csdn.net/GFJ0814/article/details/92422245 看看这篇文章(继续学习):https://www.jianshu.com/p/3 ...

  8. SpringBoot Test 多线程报错:dataSource already closed

    1:前言 最近在项目中使用多线程对大任务拆分处理时,进行数据库操作的时候报错了. 业务代码大概是这样的: @Service public calss TestServiceImpl implement ...

  9. SpringBoot中如何优雅的使用多线程

    SpringBoot中如何优雅的使用多线程 当异步方法有返回值时,如何获取异步方法执行的返回结果呢?这时需要异步调用的方法带有返回值CompletableFuture

随机推荐

  1. 使用curl出现,curl: /usr/local/lib/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)

    主要原因是curl找不到openssl的路径,所以只要将openssl的路径添加到相应的变量中就可以了. 参考连接https://blog.csdn.net/RookieWutongshu/artic ...

  2. bom操作,事件与jquery

    BOM操作中 window关键字 可以不写 DOM操作 学习如何查找节点 如何查找标签 选择器 事件 当符合某个条件下 自动触发的动作/响应 js绑定事件的方式 方式1 不推荐使用 <butto ...

  3. Google Protocol Buffer入门

    简介 Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 ...

  4. ES head

    第2种安装方式 第二种方式就是不通过Elasticsearch插件方式进行安装 1.下载elasticsearch-head的源码包 地址:https://github.com/mobz/elasti ...

  5. [SC] OpenSCManager 失败 5:拒绝访问

    问题:[SC] OpenSCManager 失败 5: 网查这个错误信息指拒绝访问  权限不足 1.解决: 以管理员身份运行cmd,即可 查询这个提示是指什么错误时,看网上有很多文章写用下面这种方法, ...

  6. [学习笔记] 可持久化线段树&主席树

    众所周知,线段树是一个非常好用也好写的数据结构, 因此,我们今天的前置技能:线段树. 然而,可持久化到底是什么东西? 别急,我们一步一步来... step 1 首先,一道简化的模型: 给定一个长度为\ ...

  7. 《剑指offer》算法题第七天

    今日题目: 复杂链表的复制 二叉搜索树与双向链表 序列化二叉树 字符串的排序 1.复杂链表的复制 题目描述: 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向 ...

  8. 小程序开发之后台mybatis逆向工程(二)

    上一节搭建好了SSM后台框架,这一节将根据表结构创建实体及映射文件以及mapper接口.如果表过多,会很麻烦,所以mybatis提供了逆向工程来解决这个问题. 上一节 SSM搭建后台管理系统 逆向工程 ...

  9. flink杂记

    flink的特点:能同时满足高性能.高吞吐.低延时,相比较于storm和spark streaming,storm的吞吐量不如flink,而spark streaming的延时比较高,因为spark ...

  10. oracle 中使用 pl/sql代码块

    1.写匿名块,输入三角形三个表的长度.在控制台打印三角形的面积. declare -- (p=(a+b+c)/2) --声明三角形的面积 三条边 的 v_a number (10,2):=&n ...