private ExecutorService executorService = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(), new NamedThreadFactory("mget-redis-pool"));
int count = Double.valueOf(Math.ceil(keys.size() / (double) 100)).intValue();
List<future<list<string>>> future = new ArrayList<>();
for(
int i = 0;
i<count;i++)
{
List<string> limitKeys = keys.stream().skip(i * 100).limit(100).collect(Collectors.toList());
future.add(executorService.submit().dataList.addAll(valueOperations.multiGet(limitKeys)));
}
try
{
for (Future<list<string>>
f:
future){
//这里要考虑dataList线程并发安全哦
dataList.addAll(f.get());
}
} catch(
Exception exception)
{
logger.error("mget汇总结果集错误,ex=", exception);
}
线程并发,搬运
最新推荐文章于 2023-02-24 11:50:33 发布