fix: reduce thread blocking by double null check in invokeMethod()#523
Merged
lukaszlenart merged 1 commit intoognl-3-4-xfrom Dec 29, 2025
Merged
Conversation
Cherry-pick of PR #521 adapted for Java 8 compatibility. Implements double-null-check pattern for _methodAccessCache and _methodPermCache to avoid synchronizing on Method objects when cache values already exist. Fixes thread contention issues where multiple threads would block waiting to acquire locks on java.lang.reflect.Method objects even when cache values were already present. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Cherry-pick of PR #521 adapted for Java 8 compatibility.
_methodAccessCacheand_methodPermCacheProblem
Production environments experienced severe thread blocking (980+ threads blocked) waiting to acquire locks on
java.lang.reflect.Methodobjects inOgnlRuntime.invokeMethod(). The root cause was that all threads competed for the same Method monitor even when cache values already existed.Solution
Move cache check outside the synchronized block (first null check), then re-check inside if null (double null check). This eliminates unnecessary synchronization when the cache is already populated.
Key Adaptations for Java 8
method.isAccessible()instead of Java 9+method.canAccess()securityManagerlogic for_methodPermCachevarusage (explicit types only)Test plan
./mvnw clean test)🤖 Generated with Claude Code