zoukankan      html  css  js  c++  java
  • 获取线程处理结果的一个方法

    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);
            }
        }
    
    }
  • 相关阅读:
    gnuplot
    charles证书安装
    jenkins 配置ssh
    jenkins 配置slave
    centos 安装jenkins
    mac的一些命令
    docker 常用命令
    GO vim环境
    go vendor目录
    protobuf
  • 原文地址:https://www.cnblogs.com/softidea/p/4733300.html
Copyright © 2011-2022 走看看