首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java急需关注的知识点-并发之使用Executor

2012-08-30 
java需要关注的知识点---并发之使用Executorpublic class CachedthreadPool {public static void main(Str

java需要关注的知识点---并发之使用Executor

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();}}

热点排行