BewareMyPower commented on PR #23217:
URL: https://github.com/apache/pulsar/pull/23217#issuecomment-2309627169

   BTW, the API document in `ConcurrentSkipListMap#computeIfAbsent` is clear 
for this behavior:
   
   ```java
        * The function
        * is <em>NOT</em> guaranteed to be applied once atomically only
        * if the value is not present.
   ```
   
   It's required by the `Map#computeIfAbsent` API documentation:
   
   ```
        * In particular, all implementations of
        * subinterface {@link java.util.concurrent.ConcurrentMap} must document
        * whether the mapping function is applied once atomically only if the 
value
        * is not present. 
   ```
   
   Here is the document for `ConcurrentHashMap`:
   
   ```java
        * The supplied
        * function is invoked exactly once per invocation of this method
        * if the key is absent, else not at all.  Some attempted update
        * operations on this map by other threads may be blocked while
        * computation is in progress, so the computation should be short
        * and simple.
        *
        * <p>The mapping function must not modify this map during computation.
   ```
   
   I believe many calls of `ConcurrentHashMap#computeIfAbsent` are not proper 
(not short and simple) or even wrong (trying to modify the map) in Pulsar, but 
it's another topic.


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to