synchronized keyword was not supposed to be reentrant ?
Synchronized block in the below code seems to be working properly as a reentrant code. I've written this to check out the reentrancy by causing a deadlock but it worked without deadlock./* This code might cause to a deadlock */
publicclass NotReentrant{
publicstaticvoid main(String[] args){
final LoggingWidget widget =new LoggingWidget();
Thread t1 =new Thread(new Runnable(){
publicvoid run(){ widget.execute();}
});
t1.start();
try{ t1.join();}catch (Exception e){}
System.out.println("You might not going to see this: There is a deadlock !");
}
}
/* dummy classes that show the proof */
class Widget{
publicsynchronizedvoid execute(){
System.out.println(toString() +" (base).execute: synchronized");
synchronized (this){
System.out.println(toString() +" (base).execute: synchronized (this)");
try{ Thread.sleep(500);}catch (Exception e){}
System.out.println(toString() +" (base).execute");
// .... code
}
}
}
class LoggingWidgetextends Widget{
publicsynchronizedvoid execute(){
System.out.println(toString() +".execute: synchronized");
super.execute();
System.out.println(toString() +".execute");
}
}

