You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benjamin Confino (Jira)" <ji...@apache.org> on 2023/10/11 17:35:00 UTC

[jira] [Created] (LANG-1716) Create a varient of LazyInitializer whch can dispose the contained object

Benjamin Confino created LANG-1716:
--------------------------------------

             Summary: Create a varient of LazyInitializer whch can dispose the contained object
                 Key: LANG-1716
                 URL: https://issues.apache.org/jira/browse/LANG-1716
             Project: Commons Lang
          Issue Type: New Feature
          Components: lang.concurrent.*
    Affects Versions: 4.0, 3.x
            Reporter: Benjamin Confino


Hello everyone.

Currently there is no clean way to dispose of an object created with a LazyInitializer. Either you callĀ _initializer.get().dispose();_ but if you've never used _initializer_ before this will invoke a potentially expensive routine just so the object can be immediately disposed.

Or you cache the result of _initializer.get();_ and then dispose the object you have cached. This means the developer has to worry about concurrency issues when disposing the object, and looses all the benefits of LazyInitializer having a built in cache.

To fix this I propose that a new variant of LazyInitializer is created, this variant will allow you to call a dispose method which will close the LazyInitializer object and then it will, if the wrapped object has been initialized, run whatever disposal routine is provided.

I have created a pull request with a potential implementation here: [https://github.com/apache/commons-lang/pull/1119] 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)