java中ExecutorService使用多线程处理业务
ExecutorService executorService = Executors.newFixedThreadPool(5); List<CancelApprovalCallable> callables = new List<>();
for(int i=0,len=idsArray.size();i<len;i++){
String id = idsArray.get(i);
CancelApprovalCallable callable = new CancelApprovalCallable(id,domain);
callables.add(callable);
}
List<Future<JSONObject>> resultList = new ArrayList<>();
try{
resultList = executorService.invokeAll(callables);
}catch(InterruptedException e){
log.error("execute concurrent thread error",e);
}finally{
if(!executorService.isShutdown() || !executorService.isTerminated()){
executorService.shutdown();
}
} /**
*批量获取线程执行结果,循环处理每条结果数据
*/
for(Future<JSONObject> future : resultList){
JSONObject resp2 = null;
try{
resp2 = future.get();
}catch(Exception e){
log.error("execute concurrent thread error",e);
}
if(resp2 == null){
continue;
}
}
class CancelApprovalCallable implements Callable<JSONbject>{
private String id;
private String domain;
CancelApprovalCallable(String id,String domain){
this.id=id;
this.domain = domain;
}
/* (non-Javadoc)
* @see java.util.concurrent.Callable#call()
*/
@Override
public JSObject call() throws Exception {
return null;
}
}
java中ExecutorService使用多线程处理业务的更多相关文章
- Java中ExecutorService和CompletionService区别
我们现在在Java中使用多线程通常不会直接用Thread对象了,而是会用到java.util.concurrent包下的ExecutorService类来初始化一个线程池供我们使用. 之前我一直习惯自 ...
- java中ExecutorService接口
一.声明 public interface ExecutorService extends Executor 位于java.util.concurrent包下 所有超级接口:Executor 所有已知 ...
- Java中涉及到金额业务的处理
一.MySql数据库中如何定义关于金额字段: 建议定义成[DECIMAL]类型,而不是float或者是double,因为这个两者是以二进制储存的,存在一定的误差.具体事例可参考https://blog ...
- java中 ExecutorService,Executor,ThreadPoolExecutor的用法
package com; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import ...
- java中有界队列的饱和策略(reject policy)
文章目录 AbortPolicy DiscardPolicy DiscardOldestPolicy CallerRunsPolicy 使用Semaphore java中有界队列的饱和策略(rejec ...
- Java中线程池,你真的会用吗?ExecutorService ThreadPoolExcutor
原文:https://www.hollischuang.com/archives/2888 在<深入源码分析Java线程池的实现原理>这篇文章中,我们介绍过了Java中线程池的常见用法以及 ...
- java并发中ExecutorService的使用
文章目录 创建ExecutorService 为ExecutorService分配Tasks 关闭ExecutorService Future ScheduledExecutorService Exe ...
- 用好JAVA中的函数式接口,轻松从通用代码框架中剥离掉业务定制逻辑
大家好,又见面了. 今天我们一起聊一聊JAVA中的函数式接口.那我们首先要知道啥是函数式接口.它和JAVA中普通的接口有啥区别?其实函数式接口也是一个Interface类,是一种比较特殊的接口类,这个 ...
- java中 immutable,future,nio
什么是Future? 用过Java并发包的朋友或许对Future (interface) 已经比较熟悉了,其实Future 本身是一种被广泛运用的并发设计模式,可在很大程度上简化需要数据流同步的并发应 ...
随机推荐
- php集成开发环境搭建三种方式
三种方式都是一键搭建php开发环境 三种方式前提都是在linux下 wamp和phpstudy就不再用了 首先打造linux开发环境,通过vagrant+vbox实现本地文件同步到虚拟机上进行同步开发 ...
- Buuctf-------WEB之admin
1.抓包扫描一把梭,无事发生地说 注释里发现 万能密码试试,报错 用的flask,pythonweb 后面发现报错页面可以调试,嘿嘿嘿 康康我们发现了什么 拿去破解,无果 于是打算代码拿下来康康,em ...
- deployment:声明式的升级应用
9.1.使用RC实现滚动升级 #kubectl rolling-update kubia-v1 kubia-v2 --image=luksa/kubia:v2 使用kubia-v2版本应用来替换运行着 ...
- Distance(2019年牛客多校第八场D题+CDQ+树状数组)
题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...
- Reset.css和Normalize.css样式表初始化相关
(1)Reset.css 简介:在HTML标签在浏览器里有默认的样式,例如 p 标签有上下边距,strong标签有字体加粗样式,em标签有字体倾斜样式.不同浏览器的默认样式之间也会有差别,例如ul默认 ...
- A and B and Lecture Rooms(LCA)
题目描述 A and B are preparing themselves for programming contests. The University where A and B study i ...
- 使用python处理selenium中的获取元素属性
# 获取我的订单元素class属性值 get_class_name = driver.find_element_by_link_text('我的订单').get_attribute('class') ...
- centos7离线部署Patroni
实验环境Centos7.7.1908 x86_64 这里说明下为什么需要安装gcc readline-devel zlib-devel这三个包,因为编译安装postgres需要用到 一.首先安装gcc ...
- RxSwift 在本质上简化了开发异步程序
RxSwift 是一个组合异步和事件驱动编程的库,通过使用可观察序列和功能样式运算符来,从而允许通过调度程序进行参数化执行. RxSwift 在本质上简化了开发异步程序,允许代码对新数据作出反应,并以 ...
- static在Swift 中表示 “类型范围作用域”
In Swift, however, type properties are written as part of the type’s definition, within the type’s o ...