While looking up pieces of code that can cause deadlocks using threads, I came across this piece of code :
Thread t1 = new Thread(){
public void run(){
while(true){
synchronized(str1){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
synchronized(str2){
System.out.println(str1 + "::"+str2);
}
}
}
}
};
After declaring and instantiating a Thread
object, it seems inside that thread the run
method is written with accompanying logic and the Thread
definition ends by closing the brace with semi colon .
What is the name of such a block of code? Is this what is called as an anonymous block?