Java — Synchronization FAQs | Code Factory

class X {
public synchronized void m1() {
// Here thread has lock of x object
Y y = new Y();
synchronized(y) {
// Here thread has lock of x and y object
Z z = new Z();
synchronized(z) {
// Here thread has lock of x, y and z object
}
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store