码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-08-16 00:29:17      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

 

 

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);
        }
    }

}

 

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

标签:

原文地址:http://www.cnblogs.com/softidea/p/4733300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!