现在的位置: 首页 > 综合 > 正文

带返回值的线程

2013年08月02日 ⁄ 综合 ⁄ 共 286字 ⁄ 字号 评论关闭
	public class PostThread implements Callable {
		private String s;
		
		public PostThread (String str) {
			this.s = h;

		}
		
		public Object call() throws Exception {
			return this.s;
		}
		
	}

使用的时候:

ExecutorService pool = Executors.newFixedThreadPool(2); 
		Callable c1 = new PostThread("hello");
		Future f1 = pool.submit(c1);
               String str = (String)f1.get();

抱歉!评论已关闭.