[java]代码库
package com.ricardozuasti;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Concurrency1 {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i<100; i++){
executor.execute(new DataProcessor(i));
}
System.out.println("Starting shutdown...");
executor.shutdown();
try {
executor.awaitTermination(100, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
System.out.println("Interrupted or timed out while awaiting termination");
}
System.out.println("All done!");
}
}//源代码片段来自云代码http://yuncode.net