ITeye博客

Thread

共 2 篇文章

线程简单运用(二)

线程的简单运用(二) Java5之前使用线程 是实现Runnable接口,没有返回值。 现在可以实现Callable接口,实现有返回值的线程。 以下是使用实例: 业务代码: import java.util.concurrent.Callable; public class MyCallable implements Callable{ private String oid; MyCallable(String oid) { this.oid = oid; } @Override public Object call() throws Exception { return oid+"任务返回…

2014-07-09 18:40 · Thread · 有返回值的线程

线程简单运用(一)

线程简单运用示例代码,两个类文件,CountThread(业务类)和 TestRecur(测试类) 首先是业务类 CountThread ,实例如下: class CountThread implements Runnable { private int count; public CountThread(int count) { this.count = count; } public void run() { getResult(count); } public static void getResult(int count){ //如果count < 10,将count扩大一倍 if …

2014-07-08 13:41 · Thread · 多线程 · 线程