Skip to content

Commit

Permalink
fix glboal asset registry instantiation issue (#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Yang Yang <[email protected]>
  • Loading branch information
yangyangv2 and Yang Yang authored Sep 29, 2024
1 parent 53ed1f5 commit 80c8b23
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ public class GlobalAssetRegistry {
private final Map<String, Class<? extends RecordTemplate>> registry = new ConcurrentHashMap<>();

private GlobalAssetRegistry() {
preLoadInternalAssets();
}

// thread-safe, lazy-load singleton instance.
// JVM guarantees static fields is only instantiated once and in a thread-safe manner when class is first being loaded.
// Putting it in the inner class makes this inner only being loaded when getInstance() is called.
private static class InnerHolder {
private static final GlobalAssetRegistry INSTANCE = new GlobalAssetRegistry();

static {
try {
INSTANCE.preLoadInternalAssets();
} catch (Exception e) {
log.error("Failed to pre-load internal assets", e);
}
}
}

private static GlobalAssetRegistry getInstance() {
Expand Down

0 comments on commit 80c8b23

Please sign in to comment.