public static void main(String[] args){ Thread t = null; try{ FutureTask<Boolean> task = new FutureTask<Boolean>(new Callable<Boolean>() { public Boolean call() throws Exception { Thread.sleep(10*100); return true; } }); t = new Thread(task); t.start(); boolean bl = task.get(10*10, TimeUnit.MILLISECONDS); System.out.println(bl); System.out.println(t.getState()); }catch(Exception e1){ e1.printStackTrace(); System.out.println(t.getState()); t.interrupt(); } try{ for(int j=0;j<13;j++){ Thread.sleep(10*10); System.out.println(j+ "" + t.getState()); } }catch(Exception e2){ e2.printStackTrace(); } }
原文地址:http://zlfwmm.blog.51cto.com/5892198/1685654