package demo01;
class Window extends Thread{
static int num=200;
String name=new String();
Window(String name){
this.name=name;
}
public synchronized void run(){
synchronized(Thread.currentThread()){
while(num>0){
System.out.println(name+"售出一张,剩余"+--num);
}
}
}
}
public class TicketSail {
public static void main(String[] args) {
try {
Window w1 = new Window("哈站");
Window w2 = new Window("哈西");
Window w3 = new Window("哈东");
w1.start();
w2.start();
w3.start();
} catch (Exception e) {
// TODO: handle exception
}
}
}
为什么num输出总有乱的,弄了好久没弄懂,求问题原因及解决方法