package com.heima.syn;
class TicketThread2 extends Thread {
private int tickedts = 50;
private Object lock = new Object();
public TicketThread2(String name){
super(name);
}
public void run(){
while(true){
synchronized (lock) {
if (tickedts > 0) {
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
System.out.println(Thread.currentThread().getName()+"正在卖第"+tickedts--+"张的票");
}else {
break;
}
}
}
}
}
public class Demo42_Ticket{
public static void main(String[] args) {
new TicketThread2("一号窗口").start();
new TicketThread2("二号窗口").start();
new TicketThread2("三号窗口").start();
new TicketThread2("四号窗口").start();
}
}
我就哭了,求哪位伙伴大神帮助呀,看了好久没有报错误,但就是运行错误,检查好几次了....
|
|