线程的随机性

 

class Demo extends Thread{
	
	@Override
	public void run() {
		 for(int i = 0;i<60;i++){
			 System.out.println(Thread.currentThread().getName()+"---"+i);
		 }
	}
}

public class ThreadDemo0 {
	public static void main(String[] args) {

	   Demo d = new Demo();
	   d.start();  //线程随机行比较明显
	 
	   for(int i= 0;i<60;i++){
		   System.out.println(Thread.currentThread().getName()+"---"+i);
	   }
	  /* for(int i= 0;i<60;i++){
		   System.out.println(Thread.currentThread().getName()+"---"+i);
	   }*/
	}

}

  

输出的结果:

main---0
main---1
main---2
main---3
Thread-0---0
Thread-0---1
Thread-0---2
Thread-0---3
Thread-0---4
Thread-0---5
Thread-0---6