ExecutorService给线程设置超时时间

走着路睡觉
  • java
小于 1 分钟

 ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); 
 final Future handler = executor.submit(new Callable(){ ... });
 executor.schedule(new Runnable(){
     public void run(){
         handler.cancel();
     }      
 }, 10000, TimeUnit.MILLISECONDS);
上次编辑于:
贡献者: zhaojingbo
Loading...