paulk-asert opened a new pull request, #2868:
URL: https://github.com/apache/groovy/pull/2868

   …tHashMap
   
   The cache was a WeakHashMap keyed on file.getAbsolutePath() or 
url.toString(). Both are freshly built strings local to getTemplate, and 
TemplateCacheEntry retains only lastModified, length, a Date and the Template, 
never the File, so nothing outside the map referred to a key once its request 
returned. Weakly held keys made every entry collectible as soon as it was 
stored, and the cache emptied at each collection however hot a template was.
   
   The map was also read and written from service() without synchronization. 
WeakHashMap did not receive the JDK 8 rewrite that ended the HashMap resize 
infinite-loop, so its transfer() still head-inserts and concurrent resizes can 
build a cycle that leaves get() spinning.
   
   ConcurrentHashMap addresses both, and is faster besides: WeakHashMap.get 
polls a ReferenceQueue on every read and dereferences a WeakReference per 
probe. Templates are now retained for the servlet's lifetime, which is bounded 
by the templates that exist, since service() answers 404 before getTemplate is 
reached for a missing file or unresolvable resource. Staleness handling is 
unchanged, as validate() still compares lastModified and length.
   
   The cache field is private and of declared type Map, TemplateCacheEntry is 
private, and only get and put are used, so the change is source and binary 
compatible.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to