黑马程序员技术交流社区

标题: Executors.newScheduledThreadPool(1).execute() 这个线程没法结束怎么办 [打印本页]

作者: 孤守星空    时间: 2014-8-23 11:02
标题: Executors.newScheduledThreadPool(1).execute() 这个线程没法结束怎么办

  1. <P>ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
  2. pool.execute(new Runnable()
  3. {
  4. public void run()
  5. {
  6. for(int i=0;i<5;i++)
  7. {
  8. long start = System.currentTimeMillis();
  9. try {
  10. Thread.sleep((int)(Math.random()*10+1)*1000);
  11. } catch (InterruptedException e) {
  12. e.printStackTrace();
  13. }
  14. long end = System.currentTimeMillis();
  15. vehicles.add(RoadCollection.this.name+"_"+i+" spending time:"+(end-start)/1000);
  16. System.out.println(vehicles.get(i));
  17. }
  18. }
  19. });</P>
  20. <P> </P>
  21. <P> </P>
复制代码






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2