Jakie jest zastosowanie synchronicznego bloku wewnątrz konstruktora?
Nie możemy tworzyć konstruktorasynchronized
ale może pisaćsynchronized
ten wewnętrzny konstruktor. W jakim przypadku taki wymóg przyjdzie? Jestem rozbawiony.
package com.simple;
public class Test {
public Test() {
synchronized (this) {
System.out.println("I am called ...");
}
}
public static void main(String[] args) {
Test test=new Test();
System.out.println(""+test);
}
@Override
public String toString() {
return "Test []";
}
}