public class ThreadTest extends Thread {
public ThreadTest(String a_Str) {
super(a_Str);
}
public synchronized void run() {
try {
int l_Time = 10000;
System.out.println(getName() + ": waiting time: " + l_Time);
wait(l_Time);
System.out.println(getName() + ": waiting completes.");
} catch (Exception e) {
e.printStackTrace();
}
}
public synchronized void _notify() {
notify();
System.out.println("notified");
}
public static void main(String[] args) {
ThreadTest l_thread = new ThreadTest("Thread1"); // (0)
l_thread.start();
try {
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}
//l_thread._notify(); // (1)
(new ThreadTest("Thread2") {
public synchronized void run() {
try {
int l_Time = 2000;
System.out.println(getName() + ": waiting timd: " + l_Time);
// Thread.sleep(2000);
notify(); // (2)
System.out.println(getName() + " notified");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
'Java Programming' 카테고리의 다른 글
org.tigris.subversion.javahl.ClientException (0) | 2009.03.07 |
---|---|
[Subclipse] Error validation location: "org.tigris.subversion.javahl. (0) | 2009.03.06 |
wrapping "sun.net.ftp.FtpClient" (0) | 2009.02.27 |
java.net.BindException: Address already in use: JVM_Bind (0) | 2009.02.10 |
java singleton 적용 (0) | 2009.02.09 |