public static void main(String[] args) throws ExecutionException, InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(3);
List<Future<?>> taskResults = new LinkedList<>();
for(int i =0; i < 10; i++){
taskResults.add(executor.submit(new CodingTask(i)));
}
System.out.println("10 task finashed");
// for (Future<?> future : taskResults){
// future.get();
// }
System.out.println("all thread finished");
executor.shutdown();
}
package handlers;
public class CodingTask implements Runnable {
public int employId;
public CodingTask(int employId) {
this.employId = employId;
}
@Override
public void run() {
System.out.println("Employee" + employId + "start writing code");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// System.out.println("Employee" + employId + "finish writing code");
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。