标签:
1 package xiancheng; 2 3 4 import java.util.Random; 5 6 public class Test2 implements Runnable { 7 8 @Override 9 public void run() { 10 11 city(); 12 13 } 14 15 public void city() 16 { 17 Random r=new Random(); 18 int s=r.nextInt(1000); 19 20 for(int i=0;i<=10;i++) 21 { 22 System.out.println(Thread.currentThread().getName()+" ,"+" 我来啦!"); 23 24 try 25 { 26 Thread.sleep(s); 27 } 28 catch(Exception e) 29 { 30 e.printStackTrace(); 31 } 32 } 33 } 34 35 public static void main(String[] args) { 36 // TODO 自动生成的方法存根 37 Test2 te=new Test2(); 38 Thread t1=new Thread(te,"云南丽江"); 39 Thread t2=new Thread(te,"乌镇"); 40 t1.start(); 41 t2.start(); 42 43 } 44 45 }
标签:
原文地址:http://www.cnblogs.com/yg6405816/p/5558227.html