You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/03/14 16:09:52 UTC

[GitHub] [jena] afs commented on issue #709: Add volatile to make method thread-safe

afs commented on issue #709: Add volatile to make method thread-safe
URL: https://github.com/apache/jena/pull/709#issuecomment-599087715
 
 
   This isn't the full case of creating a unique singleton. If it were, a volatile would be needed.
   
   It is ensuring there is late initialization so the protected methods can be overridden but any object generated by `generateAcceptedParams()` is valid.
   
   It does not have to be a uniquely created object - in that way, it differs from the singleton pattern.
   All the code does is create several objects, all of which are valid, and keeps one (the last assignment) eventually. It does not matter which on it keeps. It does not matter if threads use an object that will be dropped by a later or overlapping assignment. All the object are "same value" which is all that matters for a set.
   
   ```
       // Does not matter about race condition here because the same Set should be
       // created on any call to generateAcceptedParams.
   ```
   
   A set is "the same" if it has the same values in it.
   
   If two happen and overlap, then one pointer will overwrite the other but it's overwriting with an equivalent object and assignment of object references is atomic in Java.
   
   In the singleton pattern, it is a stronger condition - trying to create a single object once and the singleton may have varying state (e.g a cache).
   
   Thanks for checking!
   
   Is there a way to make the comments clearer?
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org