Everything You Never Wanted to Know about Java Class Initialization
summary
Class initialization runs at unpredictable times, causes deadlocks via cyclic initializers, and captures mutable external state irreversibly. Analysis of a Spring Pet Clinic build examines about 22,700 classes, finds a quarter with initializers, nearly 9,000 classes need simulation, two thirds simulate successfully and about 3,000 classes remain problematic. Common costs are 600 classes allocate a logger and 54 compile regexes at init, and default methods or reflection can trigger surprising eager initialization.
AI-written summary · about
chapters (17)
- 0:00Intro
- 0:38What is a Class Initializer
- 3:28CLN
- 5:00Cycles
- 6:30Deadlocks
- 8:20When is the class initialized
- 9:17Interfaces
- 10:37Before
- 11:01Annotation
- 13:08Find Static Wire Handle
- 14:25New Features Triggering Class Initialization
- 16:09Summary
- 19:03Application Startup Improvements
- 20:57Simulation
- 22:38Class Initialization
- 24:28Problems with Class Initialization
- 29:39Static State
related talks
54mHow Fast is Spring
52mLean Spring Boot Applications for the Cloud
41mA New Model for Java Object Initialization
41mInstrument to Remove: Using Java agents for fun and profit
49mBuilding Lean Spring Boot Applications for the Cloud
45mProject Leyden: Improving Java’s Startup Time
52mTechniques for a faster JVM start-up
48mScotty, I need Warp Speed - Ways to improve JVM startup
