[
https://issues.apache.org/jira/browse/ZOOKEEPER-1978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14068883#comment-14068883
]
Rakesh R commented on ZOOKEEPER-1978:
-------------------------------------
Yeah putIfAbsent will solve the issue. On a second look, I could see all the
occurrences of 'sessionsById' inside _synchronized methods_ except
SessionTrackerImpl#isTrackingSession(). Do we really need ConcurrentHashMap
datastructure for 'sessionsById', instead can we use simple HashMap and make
#isTrackingSession() synchronized ?
> Fix Multithreaded correctness Warnings
> --------------------------------------
>
> Key: ZOOKEEPER-1978
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1978
> Project: ZooKeeper
> Issue Type: Sub-task
> Reporter: Hongchao Deng
> Assignee: Hongchao Deng
> Priority: Minor
> Fix For: 3.5.0
>
> Attachments: ZOOKEEPER-1978.patch
>
>
> findbugs is complaining
> {code}
> if (sessionsById.get(id) == null) {
> SessionImpl s = new SessionImpl(id, sessionTimeout);
> sessionsById.put(id, s);
> }
> {code}
> is not atomic for the gap between get() and put().
> I suggest using putIfAbsent() instead.
--
This message was sent by Atlassian JIRA
(v6.2#6252)