Skip to content

This isn't the full case of creating a unique singleton. If it were, a volatile would be needed. #1

Description

@vgricak48-max

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.

Canada cape 🇨🇻 Verde Cayman islands central
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?

Originally posted by @afs in apache/jena#709 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions