Double-Checked Locking is widely cited and used as an efficient method for implementing lazy initialization in a multithreaded environment.
Unfortunately, it will not work reliably in a platform independent way when implemented in Java, without additional synchronization.
Declare a volatile local variable metadata offers a much more elegant solution
https://github.com/baidu/Jprotobuf-rpc-socket/blob/bab1e2ffc796cd8d31667474b3cdb96bbd24749d/jprotobuf-rpc-core-spring/src/main/java/com/baidu/jprotobuf/pbrpc/spring/annotation/CommonAnnotationBeanPostProcessor.java#L250-L261
Double-Checked Locking is widely cited and used as an efficient method for implementing lazy initialization in a multithreaded environment. Unfortunately, it will not work reliably in a platform independent way when implemented in Java, without additional synchronization. Declare a volatile local variable metadata offers a much more elegant solution