목차
없음
본문내용
onds
while (synchedList.isEmpty()) {
System.out.println(\"List is empty...\");
synchedList.wait(10000);
System.out.println(\"Waiting...\");
}
String element = (String) synchedList.remove(0);
return element;
}
}
// method to add an element in the list
public void addElement(String element) {
System.out.println(\"Opening...\");
synchronized (synchedList) {
// add an element and notify all that an element exists
synchedList.add(element);
System.out.println(\"New Element:\'\" + element + \"\'\");
synchedList.notifyAll();
System.out.println(\"notifyAll called!\");
}
System.out.println(\"Closing...\");
}
public static void main(String[] args) {
final ObjectDemo demo = new ObjectDemo();
Runnable runA = new Runnable() {
public void run() {
try {
String item = demo.removeElement();
System.out.println(\"\" + item);
} catch (InterruptedException ix) {
System.out.println(\"Interrupted Exception!\");
} catch (Exception x) {
System.out.println(\"Exception thrown.\");
}
}
};
Runnable runB = new Runnable() {
// run adds an element in the list and starts the loop
public void run() {
demo.addElement(\"Hello!\");
}
};
try {
Thread threadA1 = new Thread(runA, \"A\");
threadA1.start();
Thread.sleep(500);
Thread threadA2 = new Thread(runA, \"B\");
threadA2.start();
Thread.sleep(500);
Thread threadB = new Thread(runB, \"C\");
threadB.start();
Thread.sleep(1000);
threadA1.interrupt();
threadA2.interrupt();
} catch (InterruptedException x) {
}
}
}
비고 및 고찰
Bed smell 이 느껴지는 프로그램에 대하여 찾으면서 저 자신이 실력이 얼마나 없는지 깨닫게 되었습니다.
이런것과, 이런 것이 잘못
while (synchedList.isEmpty()) {
System.out.println(\"List is empty...\");
synchedList.wait(10000);
System.out.println(\"Waiting...\");
}
String element = (String) synchedList.remove(0);
return element;
}
}
// method to add an element in the list
public void addElement(String element) {
System.out.println(\"Opening...\");
synchronized (synchedList) {
// add an element and notify all that an element exists
synchedList.add(element);
System.out.println(\"New Element:\'\" + element + \"\'\");
synchedList.notifyAll();
System.out.println(\"notifyAll called!\");
}
System.out.println(\"Closing...\");
}
public static void main(String[] args) {
final ObjectDemo demo = new ObjectDemo();
Runnable runA = new Runnable() {
public void run() {
try {
String item = demo.removeElement();
System.out.println(\"\" + item);
} catch (InterruptedException ix) {
System.out.println(\"Interrupted Exception!\");
} catch (Exception x) {
System.out.println(\"Exception thrown.\");
}
}
};
Runnable runB = new Runnable() {
// run adds an element in the list and starts the loop
public void run() {
demo.addElement(\"Hello!\");
}
};
try {
Thread threadA1 = new Thread(runA, \"A\");
threadA1.start();
Thread.sleep(500);
Thread threadA2 = new Thread(runA, \"B\");
threadA2.start();
Thread.sleep(500);
Thread threadB = new Thread(runB, \"C\");
threadB.start();
Thread.sleep(1000);
threadA1.interrupt();
threadA2.interrupt();
} catch (InterruptedException x) {
}
}
}
비고 및 고찰
Bed smell 이 느껴지는 프로그램에 대하여 찾으면서 저 자신이 실력이 얼마나 없는지 깨닫게 되었습니다.
이런것과, 이런 것이 잘못
소개글