Executor线程池提交任务

来源:互联网 发布:如何将mac 设置成中文 编辑:程序博客网 时间:2024/05/22 03:52
ExecutorService service = Executors.newSingleThreadExecutor();          for (int i = 0; i < 4; i++) {              Runnable run = new Runnable() {                  @Override                  public void run() {                      System.out.println("thread start:"+this.hashCode());                      try {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}                    System.out.println("thread end:"+this.hashCode());                 }              };              service.execute(run);          }          service.shutdown();          try {service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}          System.out.println("all thread complete"); 

0 0
原创粉丝点击