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");
}
}

最新文章

  1. wamp 局域网访问
  2. XCode8向ITunes提交版本,不显示或提示无效的版本
  3. SPOJ DQUERY D-query(主席树)
  4. 【Python全栈笔记】05 [模块二] 19 Oct 文件的操作
  5. 安卓开发笔记——关于图片的三级缓存策略(内存LruCache+磁盘DiskLruCache+网络Volley)
  6. 代码分享:php对二维数组进行排序
  7. spring中配置jndi数据源
  8. Python内置函数(13)——bytearray
  9. 第25月第2天 Django-By-Example项目记录01
  10. 国外优秀C/C++网站
  11. 剑指offer(22)从上往下打印二叉树
  12. error: ‘kEmptyString’ is not a member of ‘google::protobuf::internal’
  13. python --- 23 模块 os sys pickle json
  14. 添加多个CCArmature
  15. MySQL 用户管理及权限管理
  16. Matlab图形调色
  17. LeetCode - Customers Who Never Order
  18. OGG生成数据定义文件的参数NOEXTATTR
  19. springboot初学
  20. EF Code-First 学习之旅 EntityTypeConfiguration&lt;TEntity&gt;

热门文章

  1. (十)zabbix监控TCP状态
  2. 报表开发神器!DevExpress Reporting v19.1全平台新功能解析
  3. HDU-1358-Period(KMP, 循环节)
  4. react 项目 mock数据
  5. 【C#-程序时间计数器】如何计算某些步骤/过程耗时多少?
  6. Java进阶知识07 Hibernate一对一双向外键关联(Annotation+XML实现)
  7. 回文数二(acm训练)
  8. CDOJ 1135 邱老师看电影 概率dp
  9. K8S中Service
  10. sh_14_字符串定义和遍历