获取线程处理结果的一个方法

 

 

package thread.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @创建人:helloworld.tang@qq.com
 * @创建时间:2015-8-15 下午10:32:23
 * 
 */

public class ThreadFiledValue {

    /**
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {

        Task task = new Task();
        Thread thread = new Thread(task);
        thread.start();
        while (thread.isAlive()) {
            System.out.println(Thread.currentThread() + "is alive");
        }
        for (String temp : task.getList()) {
            System.out.println(temp);
        }

    }

}

class Task implements Runnable {
    private List<String> list = new ArrayList<String>();

    public List<String> getList() {
        return list;
    }

    public void run() {
        for (int i = 0; i < 10; i++) {
            list.add(Thread.currentThread() + ":no->" + i);
        }
    }

}

 

上一篇:python学习方法总结(内附python全套学习资料)


下一篇:Deep Learning framework --- MexNet 安装,测试,以及相关问题总结