Thead线程篇之-----多线程 实现 有返回值的功能
2014-07-09 14:58
281 查看
import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; public class MyCallBack implements Callable<String>{ private String threadName; public MyCallBack() { } public MyCallBack(String theadName) { this.threadName = theadName; } public String call() throws Exception { for (int i = 0; i < 100; i++) { System.out.println(threadName+"===>\t"+i); } return threadName+"\t is over"; } public static void main(String[] args) { MyCallBack callBack = new MyCallBack("thread0"); FutureTask<String> taskList = new FutureTask<String>(callBack); Thread t = new Thread(taskList); t.start(); try { for (int i = 0; i < 100; i++) { System.out.println("thread1===>\t"+i); } while(!taskList.isDone()){ System.out.println(taskList.get()); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } }
相关文章推荐
- 通过PHP pcntl函数实现多线程功能
- php来实现telnet的连接、传递命令、获取返回值等功能!
- python实现多线程暴力破解登陆路由器功能代码分享
- Android开发之多线程中实现利用自定义控件绘制小球并完成小球自动下落功能实例
- cocos2dx 新方法 实现多线程加载plist功能
- Java多线程-一个简单的线程,实现挂起和恢复的功能
- python 多线程 基于正则表达式的多线程文本替换功能实现
- 使用实现Runnable的多线程,实现秒表计时器功能
- 多线程的3中实现方式,以及有返回值线程池Demo
- .net多线程传参与接收返回值实现办法
- 多线程实现买票功能
- MFC中 使用多线程实现语音播放功能
- Android开发(14)-- 多线程中实现利用自定义控件绘制小球并完成小球自动下落的功能
- 通过WEB服务器来实现PHP多线程功能
- Linux网络编程--多线程实现echo服务器与客户端“一对多”功能,是网络编程的“Hello World!”
- 【Java Socket】【Flex Socket】【Java 多线程】实现基本聊天功能demo
- Linux用多线程和socket实现跨机器的聊天通信功能
- Java多线程实现下载功能
- 有返回值的多线程的实现:FutureTask+Callable
- Linux网络编程--多线程实现echo服务器与客户端“一对多”功能,网络编程的“Hello World!” - 壮壮熊