Java tutorial
//package com.java2s; import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import com.google.common.collect.Lists; public class Main { public static <T> List<Future<T>> call(int thred, Callable<T> callable) { ExecutorService es = Executors.newCachedThreadPool(); List<Future<T>> list = Lists.newArrayList(); for (int i = 0; i < thred; i++) { list.add(es.submit(callable)); } return list; } public static <T> List<Future<T>> call(Collection<Callable<T>> callables) { ExecutorService es = Executors.newCachedThreadPool(); List<Future<T>> list = Lists.newArrayList(); for (Callable<T> callable : callables) { list.add(es.submit(callable)); } return list; } }