//执行多任务类
public Map<String,Object> tasks(List<PddAccount> pddAccounts,int length) throws InterruptedException {
Map<String,Object> map=new HashMap<>();
List<PddAccount> rlist=new ArrayList<>();
ExecutorService pool = Executors.newFixedThreadPool(30);
for (int i = 0; i < pddAccounts.size(); i++) {
PddAccount account = pddAccounts.get(i);
try{
Callable<Object> callable = new Callable<Object>() {
@Override
public Object call() throws Exception {
boolean validAccountAndLength = getValidAccountAndLength(account);
return validAccountAndLength;
}
};
Future<Object> future = pool.submit(callable);
boolean o = (boolean)future.get();
if(o){
rlist.add(account);
}
if(rlist.size() >= length){
pool.shutdown();//快速关闭线城池
map.put("list",rlist);
return map;
}
}catch (Exception e){
System.out.println("出现异常");
}
}
map.put("list",rlist);
return map;
}