-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Description
Lines 250 to 261 in bab1e2f
if (metadata == null) { | |
synchronized (this.injectionMetadataCache) { | |
metadata = this.injectionMetadataCache.get(clazz); | |
if (metadata == null) { | |
LinkedList<InjectionMetadata.InjectedElement> elements; | |
elements = new LinkedList<InjectionMetadata.InjectedElement>(); | |
parseFields(clazz, annotion, elements); | |
parseMethods(clazz, annotion, elements); | |
metadata = new InjectionMetadata(clazz, elements); | |
this.injectionMetadataCache.put(clazz, metadata); | |
} |
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
Metadata
Metadata
Assignees
Labels
No labels