这段java多线程代码有问题吗?
public class Main {
public static void main(String[] args) {
MyThread mt = new MyThread();
new Thread(mt).start();
new Thread(mt).start();
new Thread(mt).start();
}
}
class MyThread implements Runnable {
private int ticket = 20;
public void run() {
for (int i = 0; i < 20; i++) {
if (this.ticket > 0) {
System.out.println("线程:"+Thread.currentThread().getName()+" 卖票:ticket" + this.ticket--);
}
}
}
}
帕♂秋♂莉♂
11 years, 2 months ago