Am I correct in my assumption about synchronized block?
- by kunjaan
I have a method shout() with a synchronized block.
private void shout(){
System.out.println("SHOUT " + Thread.currentThread().getName());
synchronized(this){
System.out.println("Synchronized Shout" + Thread.currentThread().getName());
try {
Thread.sleep(50);
}
catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Synchronized Shout" + Thread.currentThread().getName());
}
}
If I have two Threads that run this method, am I correct in assuming that the two "Synchronized Shout" will always appear one after the other? There can be no other statements in between the "Synchronized Shout"?