반응형

producer.java


package custom;


public class producer extends Thread {

	private Product myW;
	
	public producer(Product vec){
		myW = vec;
	}
	
	public void run(){
		for(char ch = 'A'; ch<='Z'; ch++){
			System.out.println("생산자가 제품" + ch + "을 생산했습니다");
			myW.put(ch);
		}
	}
}


consumerMain.java



package custom;


public class consumerMain {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Product share = new Product();

		producer th1 = new producer(share);
		Customer th2 = new Customer(share);
		
		th1.start();
		th2.start();
	}

}



Customer.java


package custom;


public class Customer extends Thread {

	private Product myW;
	
	public Customer(Product vec){
		myW = vec;
	}
	
	public void run(){
		char ch;
		for(int i = 0; i < 26; i++){
			ch = myW.get();
			System.out.println("소비자가 " + ch + "소비 했습니다.");
		}
	}
	
}


+ Recent posts