public class ThreadDemo1{
public static void main(String[] args){
ThreadTest t = new ThreadTest();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
}
}
class ThreadTest implements Runnable{
private int ticket = 10;
public void run(){
while(true){
if(ticket > 0){
System.out.println(Thread.currentThread().getName() +
" is saling ticket" + ticket--);
}else{
break;
}
}
}
}
//class ThreadTest extends Thread{
// private int ticket = 10;
// public void run(){
// while(true){
// if(ticket > 0){
// System.out.println(Thread.currentThread().getName() +
// " is saling ticket" + ticket--);
// }else{
// break;
// }
// }
// }
//}