java需要关注的知识点---并发之使用Executor
程序员文章站
2022-03-23 14:59:09
...
public class CachedthreadPool {
public static void main(String[] args) {
ExecutorService es = Executors.newCachedThreadPool();
for ( int i = 0; i< 5; i++)
es.execute(new LiftOff());
es.shutdown();
}
}
public class MoreBasicThread {
/**
* @param args
*/
public static void main(String[] args) {
for (int i = 0; i< 5; i++) {
new Thread(new LiftOff()).start();
}
System.out.println("Waiting for liftOff");
}
}
public class SingleThreadExecutor {
public static void main(String[] args) {
// 保证无论何时都只有一个线程在运行。
ExecutorService es = Executors.newSingleThreadExecutor();
for(int i = 0; i < 5; i++) {
es.execute(new LiftOff());
}
es.shutdown();
}
}
上一篇: C++ Vector
下一篇: STL string类