1223 Lessons Learned

Examples of multi-threaded practice

Ticketing

class TicketWindow2 implements Runnable{
private int tickets=100;
public void run();{
while(true){
if(tickets>0){
System.out.println(Thread.currentThread().getName());
}
}
}
}
public calss Example{
public static void main(String args[]){
TicketWindow2 tw=new TicketWindow();
new Thread(tw,“窗口1”).start();
new Thread(tw,“窗口2”).start();
new Thread(tw,“窗口3”).start();
new Thread(tw,“窗口4”).start();
}
}

Guess you like

Origin blog.51cto.com/14589602/2461516