activeCount()
不是开启了 t1 t2 ( t1.start() t2.start() )吗?怎么不是三个线程?
public class multiThread2 extends Thread{
private int data;
public multiThread2(String name, int p){
super(name);
data = p;
}
public void run(){
for(int i = data;i<20;i+=2){
System.out.println(i);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
multiThread2 t1, t2;
t1 = new multiThread2("odd",1);
t2 = new multiThread2("even",2);
t1.start();
t2.start();
System.out.println("thread:"+activeCount());
}
}
运行结果:
1
3
5
7
9
11
13
15
17
19
thread:2
2
4
6
8
10
12
14
16
18