[ 
https://issues.apache.org/jira/browse/LANG-678?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Oliver Heger resolved LANG-678.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 3.0

Patch applied in revision 1071402.

> Add support for ConcurrentMap.putIfAbsent()
> -------------------------------------------
>
>                 Key: LANG-678
>                 URL: https://issues.apache.org/jira/browse/LANG-678
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.concurrent.*
>            Reporter: Oliver Heger
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: putIfAbsent.patch
>
>
> The ConcurrentMap interface provides the {{putIfAbsent()}} method for adding 
> keys which are not yet present in the map in an atomic operation. However, 
> using this method is not always convenient because in many cases the return 
> value is not what you want: If the value is newly added, *null* is returned. 
> Typically the calling code is rather interested in the value which is now 
> stored in the map. This is a proposal to add a new {{putIfAbsent()}} method 
> to {{ConcurrentUtils}} which returns this value.
> Also, when working with a concurrent map, a typical pattern is to check 
> whether the map contains a key. If not, a value is created and put into the 
> map - unless another thread was faster. An example of such a use case is a 
> map acting as a cache. {{ConcurrentUtils}} can provide support for such use 
> cases by combining the {{putIfAbsent()}} operation with a 
> {{ConcurrentInitializer}}: If the key is not found in the map, the 
> initializer is called to create the corresponding value. Finally, 
> {{putIfAbsent()}} is called to add the value to the map.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to