codeboy__
2017-04-21 09:01
这和不同机器的时钟周期数有关吗,或者是开发环境?我用的是myeclipse JDK1.6
public class Actor extends Thread { public void run() { int count = 0; boolean keepRunning = true; System.out.println(getName() + "是一个演员"); while (keepRunning) { System.out.println(getName() + "登台演出: " + (++count)); if (count == 100) { keepRunning=false; } if(count%10==0){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } System.out.println(getName() + "演出结束"); } public static void main(String[] args) { Actor actor = new Actor(); actor.setName("Mr.Thread"); actor.start(); Thread actress=new Thread(new Actress(),"Ms.Runnble"); actress.start(); } } class Actress implements Runnable{ @Override public void run() { // TODO Auto-generated method stub int count = 0; boolean keepRunning = true; System.out.println(Thread.currentThread().getName() + "是一个演员"); while (keepRunning) { System.out.println(Thread.currentThread().getName() + "登台演出: " + (++count)); if (count == 100) { keepRunning=false; } if(count%10==0){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } System.out.println(Thread.currentThread().getName() + "演出结束"); } }
线程的结果动态性
深入浅出Java多线程
186088 学习 · 464 问题
相似问题