I have the below code and trying to understand why the synchronization is not achieved here:
class Main {
Thread t1 = new OpenServerSockets();
t1.start();
}
public class OpenServerSockets extends Thread {
@Override
public void run() {
while(true){
Thread t = new ClientResponder(clientSocket, dis, dos);
t.start();
}
}
public class ClientResponder extends Thread {
@Override
public void run(){
synchronized(this) {
// some other static method call in another class.
}
}
}
The synchronized block gets called by multiple threads at the same time. Why is it so? Isn't synchronized block used this way not supposed to ensure mutual exclusion execution of code?