要求:用两个线程模拟存票.售票过程.但要求每存入一张票,就售出一张票,售出后,再存入,直到售完为止. 用到的知识点:线程等待.唤醒.可能的线程中断异常 下面的方式一和方式二采用的是唤醒所有等待的线程,即wait()和notify()方法 方式一:继承Thread class Tickets //定义(资源)票类 { protected int size;//总票数 int number=0; //票号 Boolean available=false;//表示当前是否有票可售 public Tic…
package 生产者和消费者; //消费者 public class Customer implements Runnable { private Share_resources rescources=null; public Customer( Share_resources rescources){ this.rescources=rescources; } public void run() { for (int i = 0; i <50; i++) { rescources.popup…