Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------
- Object lock = new Object();
- //Thread A:
- synchronized(lock) {
- lock.notifyAll();
- runBeforeThreadBisNotified();
- }
- //-----
- //Thread B:
- synchronized(lock) {
- lock.wait();
- runOnNotificationFromThreadA();
- }
- //---------------------------------
- final Lock lock = new ReentrantLock();
- final Condition cond = lock.newCondition();
- //Thread A:
- lock.lock();
- try {
- cond.signal();
- runWhenThreadBisFinished() ;
- } finally {
- lock.unlock();
- }
- //-----
- //Thread B:
- lock.lock();
- try {
- cond.await();
- runWhenSignaled() ;
- } finally {
- lock.unlock();
- }
- //---------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement