Every Object in java has synchronisation mechanism for multithreading. You can use
wait() and
notify() methods on any object to synchronise your multithreaded logic. As an example
Object lock = new Object();
// later ..
synchronized (lock) {
lock.wait(); // Will block until lock.notify() is called on another thread.
}
// Somewhere else...
synchronized (lock) {
lock.notify(); // Will wake up lock.wait()
}
Other options are not present in Object class methods.
Login in to like
Login in to comment