标签:waiting color out 回收 线程 java 执行 private reads
定义任务
public class LiftOff implements Runnable{ protected int countDown = 10; private static int taskCount = 0; private final int id = taskCount++; public LiftOff(){} public LiftOff(int countDown){ this.countDown = countDown; } public String status() { return "#"+id+"("+(countDown>0?countDown:"Liftoff!")+"). "; } @Override public void run() { while(countDown-->0){ System.out.println(status()); Thread.yield(); } } }
使用Thread类驱动任务
public class BasicThreads { public static void main(String[] args) { Thread t = new Thread(new LiftOff()); t.start(); System.out.println("Waiting for LiftOff"); } }
任务执行完之前垃圾回收器不会回收线程对象。
标签:waiting color out 回收 线程 java 执行 private reads
原文地址:http://www.cnblogs.com/yumo/p/6151955.html