java并发资源访问_01

package Java多线程_01;
class MyThread_01 implements Runnable{
	private int ticket = 5;
	@Override
	public void run() {
		for(int x=0;x<100;x++) {
			if(ticket>0) {
				System.out.println("卖票,ticket="+this.ticket--);
			}
		}
	}
}
public class 并发资源访问_01 {
	public static void main(String[] args) {
		MyThread_01 mt = new MyThread_01();
		new Thread(mt).start();
		new Thread(mt).start();
		new Thread(mt).start();
	}
}

  

原文地址:https://www.cnblogs.com/sunzhongyu008/p/11150116.html