标签:支持 read public style 时间 color nbsp [] 单线程
JAVA提供4种缓存线程池
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 缓存线程池
* 缓存线程池可以提高程序性能
* 长时间闲置的不会占用资源
* */
public class MyCache {
public static void main(String[] args) {
ExecutorService exec = Executors.newCachedThreadPool();
for (int index = 0; index < 10; index++) {
Runnable run = new Runnable() {
public void run() {
long time = (long) (Math.random() * 1000);
System.out.println("sleep:" + time + " ss ");
try {
Thread.sleep(time);
} catch (Exception e) {
}
}
};
exec.execute(run);
}
exec.shutdown();
}
}
标签:支持 read public style 时间 color nbsp [] 单线程
原文地址:http://www.cnblogs.com/zique/p/6152845.html