public static void main(String args) Thread1 t1= new Thread1( Thread1",1) ∥)创建线程对象 Thread 1 t2= new Thread1( Thread2, 2) t1.start ∥动执行线程 t2.start System. out. printIn activeCount="+t2. active Counto
public static void main (String args[]) { Thread1 t1 = new Thread1("Thread1",1); //创建线程对象 Thread1 t2 = new Thread1("Thread2",2); t1.start(); //启动执行线程 t2.start(); System.out.println("activeCount="+t2.activeCount()); } }
例7.1的运行结果 D: \myjava>javac Thread1.java D: Myjava>java thread 1 active Count=3 Thread1:13579111315171921232527 Thread2:246810121416182022242628 30323436384042444648 Thread2end! 2931333537394143454749 Thread1end
例7.1的运行结果 D:\myjava>javac Thread1.java D:\myjava>java Thread1 activeCount=3 Thread1: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 Thread2: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 Thread2 end! 29 31 33 35 37 39 41 43 45 47 49 Thread1 end!