D DeVice wrote:I think Paul is implying that you should declare a private constructor for your class so it cannot be instantiated outside of your class.
BEE MBA PMP SCJP-6
Static final initialization requires StoreStore barriers that are normally entailed in mechanics needed to obey Java class loading and initialization rules.
The rules for class initialization ensure that any thread that reads a static field will be synchronized
with the static initialization of that class, which is the only place where static final fields can be
set. Thus, no special rules in the JMM are needed for static final fields.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
I think in context of thread safety final is used to make an object immutable.
Also since final in new JMM has a changed meaning which says that if the variables of a class are final, then during the instantiation, all those variables will get properly initialized value before the reference of that instance is made visible to other threads.
2) The internal Data Structure(which contains the constant pool) in the runtime area is thread safe, which is used by the classloader to load the class and create a .class instance. Now since Static initialization happens just after the class is loaded by the class loader and its .class instance is created in the heap, it remains questionable whether the assignment of appropriate values to static variables is thread safe or not.
The rules for class initialization ensure that any thread that reads a static field will be synchronized
with the static initialization of that class, which is the only place where static final fields can be
set. Thus, no special rules in the JMM are needed for static final fields.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5