Menu



Manage

Cord > Study_JAVA 전체 다운로드
파일 목록
Study_JAVA > 13/DataBox.java Lines 32 | 627 바이트
다운로드

                        package week13;

public class DataBox {
	private String data;

	public synchronized String getData() {
		if(this.data == null)
			try {
				wait();
			} catch (InterruptedException e) {}
		
		String returnValue = this.data;
		System.out.println("Consumer's read data : " + returnValue);
		
		this.data = null;
		notify();
		return returnValue;
	}

	public synchronized void setData(String data) {
		if(this.data != null) {
			try {
				wait();
			} catch (InterruptedException e) {}
		}
		this.data = data;
		System.out.println("Producer Thread's making data : " + this.data);
		notify();
	}
	
}