java futuretask的基本应用

public static void main(String args[]) throws InterruptedException, ExecutionException {
		
		Callable<String> c=new Callable<String>() {

			@Override
			public String call() throws Exception {
				// TODO Auto-generated method stub
				Thread.sleep(1000);
				return "done ...";
			}
			
		};
		
		FutureTask<String> ft=new FutureTask<String>(c);
		
		new Thread(ft).start();
		
		System.out.println("wait to be done ...");
		
		System.out.println(ft.get());
	}

执行结果

wait to be done ...
done ...

猜你喜欢

转载自blog.csdn.net/caideb/article/details/86008555