Cache validation chain as singleton via Initialization-on-Demand Holder
Previously getValidationChain() rebuilt ~24 linked ValidationChain nodes
on every annotation-per-field call, generating unnecessary GC pressure.
All nodes are stateless so a single shared instance is safe.

- Introduce private static ChainHolder inner class in Validator; the
  chain is built once on first class access and reused for all callers
- Replace per-call getValidationChain() + lengthChain/mathChain/stringChain
  helpers with ChainHolder.CHAIN reference at the call site
- Mark ValidationChain.nextChain volatile for defence-in-depth thread
  safety on the shared singleton
- Add chainForTesting() package-private accessor
- Add ValidatorChainCachingTest: same-instance identity check and
  correctness under 16-thread x 1000-call concurrent load

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bd0c96b commit 5e16af9468130cdc2d8873637841d33e76c92274
@Alexander Ljunggren Alexander Ljunggren authored on 6 May
Showing 3 changed files
View
src/main/java/io/ljunggren/validator/Validator.java
View
src/main/java/io/ljunggren/validator/validation/ValidationChain.java
View
src/test/java/io/ljunggren/validator/ValidatorChainCachingTest.java 0 → 100755