package thread.demo; import java.util.ArrayList; import java.util.List; /** * @Description: * @创建人:[email protected] * @创建时间: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); } } }
时间: 2024-10-24 12:25:38