Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-609

Support lazy initialization using atomic variables

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0
    • lang.concurrent.*
    • None

    Description

      In the new concurrent package there is already the LazyInitializer class implementing the double-check idiom for lazy initialization of instance fields. Another way to perform initialization lazily would be the usage of atomic variables. This solution would not need synchronization at all. If there is low contention (not many threads in parallel), it is more efficient than synchronized access. Its drawback is that the initialization may be done multiple times if multiple threads access the initializer almost at the same time (however, it can be guaranteed that always the same object created by the initializer is returned).

      This is a proposal to add an AtomicInitializer class as an alternative to LazyInitializer that operates on AtomicReference variables.

      In order to make the initializers smoothly exchangable, it would make sense for them to share a common interface. This interface could also be implemented by the BackgroundInitializer class.

      Attachments

        1. AtomicInitializer.patch
          25 kB
          Oliver Heger

        Activity

          People

            Unassigned Unassigned
            oheger Oliver Heger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: