Partial thread safe (merge #154 first) #155
Merged
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.
@samskivert
This PR builds on top of #154 . Merge that one first and I will rebase it on
master
and then you can merge it.It fixes two problems:
_template
should be volatile regardless of locksWithout the lock in a highly threaded environment the template can re-parsed an overwhelming amount of times.
For example the unit test code shows how the template can be loaded and parsed 63 times!
With the advent of Virtual Threads in JDK 21 you can have this happen way more often and if the template is coming from a database call this can be very expensive and outweighs the additional overhead of a lock (in almost all cases regardless of where the template comes from).
If you are wondering why
_template
never had threading problems (e.g. NPE on _template beingnull
) not beingvolatile
is because in 64 bit platforms all references are inherently atomic but this is not the case for 32 bit platforms like Raspberry PI or other JVM implementations.