public class NumberThread extends Thread {
private int k;
public NumberThread(String name,int k) {
super(name);
this.k = k;
}
public NumberThread(String name) {
this(name,0);
}
public synchronized void run() {
int i = k;
System.out.print("\n"+this.getName()+": ");
while(i<50) {
System.out.print(i+" ");
i+=2;
}
System.out.println(this.getName()+"结束!");
}
public static void main(String[] args) {
NumberThread thread_odd = new NumberThread("奇数线程",1);
NumberThread thread_even = new NumberThread("偶数线程",2);
thread_odd.start();
thread_even.start();
System.out.println("activeCount="+thread_even.activeCount());
}
}
怎么结果是
activeCount = 3
奇数线程:
偶数线程:2 4 1 6 3 5 7 .....46 48 47 偶数线程结束!
49 奇数线程结束!
我用了synchronized啊
那位高手帮我下 我好郁闷啊
private int k;
public NumberThread(String name,int k) {
super(name);
this.k = k;
}
public NumberThread(String name) {
this(name,0);
}
public synchronized void run() {
int i = k;
System.out.print("\n"+this.getName()+": ");
while(i<50) {
System.out.print(i+" ");
i+=2;
}
System.out.println(this.getName()+"结束!");
}
public static void main(String[] args) {
NumberThread thread_odd = new NumberThread("奇数线程",1);
NumberThread thread_even = new NumberThread("偶数线程",2);
thread_odd.start();
thread_even.start();
System.out.println("activeCount="+thread_even.activeCount());
}
}
怎么结果是
activeCount = 3
奇数线程:
偶数线程:2 4 1 6 3 5 7 .....46 48 47 偶数线程结束!
49 奇数线程结束!
我用了synchronized啊
那位高手帮我下 我好郁闷啊