【发布时间】:2021-06-08 14:51:36
【问题描述】:
我有这个循环为每个线程设置作业 我的问题是如何在同一个循环中启动线程,并避免另一个循环
List<Thread> works= new ArrayList<Thread>();
for (final action a : actions) {
threads.add(new Thread(() -> {
jobMethod(a);
}));
}
这是我想避免的:
for (Thread t : threads) {
t.start();
}
【问题讨论】:
标签: java multithreading thread-safety