FutureTask用法
FutureTask:类似于Runnable,和Runnable的区别在于他有一个返回值,
且外部调用该futureTask的get方法时。当前线程将被阻塞,直至get方法执行结束。
FutureTask<String> futureTask=new FutureTask<String>(new Callable<String>() {
public String call() throws Exception {
Thread.sleep(1000);
return "zl";
}
});
new Thread(futureTask).start();
long a=System.currentTimeMillis();
System.out.println("data:"+futureTask.get());
System.out.println("time:"+(System.currentTimeMillis()-a));