Wednesday, May 23, 2012

Java wait(), notify()

Java Multithread wait(), notify() must know.

1. Object use to lock must be static, each object have it own wait().

2. Locked object must release by own monitor, e.g :

            public static Object lock = new Object();

                        synchronized(lock) {
lock.wait(RES_WAIT_TIMEOUT);
}

            //on other thread


                synchronized(lock) {
lock.notify();
}

No comments:

Post a Comment