package producerAndCustomer;import java.util.ArrayList;import java.util.List;public class Plate { private List
package producerAndCustomer;public class Add implements Runnable { private Plate applePlate; private Object apple = new Object(); public Add(Plate applePlate){ this.applePlate = applePlate; } @Override public void run() { // TODO Auto-generated method stub for(int i = 0 ;i<5;i++){ applePlate.putApple(apple); } }}
package producerAndCustomer;public class Get implements Runnable { private Plate applePlate; public Get(Plate applePlate){ this.applePlate = applePlate; } @Override public void run() { // TODO Auto-generated method stub for(int i=0;i<5;i++){ applePlate.getApple(); } }}
package producerAndCustomer;public class SynchroTest { public static void main(String args[]){ Plate myPlate = new Plate(); new Thread(new Get(myPlate)).start(); new Thread(new Add(myPlate)).start(); }}