eclipse-ee4j / glassfish-shoal

Shoal
Other
5 stars 9 forks source link

DistributedStateCacheImpl not thread safe? #79

Closed glassfishrobot closed 14 years ago

glassfishrobot commented 15 years ago

Hello,

tho i see several issues, i concentrate myself only on one, the most obvious:

private static final Map<String, DistributedStateCacheImpl> ctxCache = new HashMap<String, DistributedStateCacheImpl>(); //return the only instance we want to return static DistributedStateCache getInstance(final String groupName) { DistributedStateCacheImpl instance; if (ctxCache.get(groupName) == null)

{ instance = new DistributedStateCacheImpl(groupName); ctxCache.put(groupName, instance); }

else

{ instance = ctxCache.get(groupName); }

return instance; }

I think, shoal should take care of concurrency issues on ctxCache as well.

Why not using ConcurrentMap as well? Maybe like this (which works fine, as long instantiating an instance is not a heavy operation):

ConcurrentMap<String, DistributedStateCacheImpl> ctxCache = ...;

static DistributedStateCache getInstance(final String groupName) { DistributedStateCacheImpl instance = ctxCache.get(groupName); if (instance == null) { instance = new DistributedStateCacheImpl(groupName);

// put our mapping only, if no other mapping has been put already DistributedStateCacheImpl otherInstance = ctxCache.putIfAbsent(groupName, instance);

// there was another mapping, use that one instead of ours if (otherInstance != null)

{ instance = otherInstance; }

} return instance; }

Other issues:

Right now it seems, someone has to synchronize on its own. At least this should be reflected in the javadoc:

"The implemenation itself is not thread-safe"

What do you think?

Environment

Operating System: All Platform: All

Affected Versions

[current]

glassfishrobot commented 6 years ago
glassfishrobot commented 15 years ago

@glassfishrobot Commented Reported by okrische

glassfishrobot commented 15 years ago

@glassfishrobot Commented shreedhar_ganapathy said: Excellent observation! Could you also file cases for other issues you see with DistributedCache ? Are you interested in contributing fixes? We always will welcome those.

glassfishrobot commented 15 years ago

@glassfishrobot Commented okrische said: You want me to submit a patch on this issue? I can do, will you append it then to the branch?

glassfishrobot commented 15 years ago

@glassfishrobot Commented shreedhar_ganapathy said: We'd be happy to do that. If you send the contributor agreement, you will have commit access to check in your patch after review and some testing.

Thanks Shreedhar

glassfishrobot commented 15 years ago

@glassfishrobot Commented okrische said: Created an attachment (id=11) patch to fix concurrency issues for this class only

glassfishrobot commented 15 years ago

@glassfishrobot Commented okrische said: Okay, here some comments to the patch:

glassfishrobot commented 15 years ago

@glassfishrobot Commented okrische said: Ups.

-> meant "ctxCache", not cache

glassfishrobot commented 15 years ago

@glassfishrobot Commented @jfialli said: Thanks for the patch. I will verify the changes against our internal Shoal tests. If all checks out, I will update this issue, requesting you to check the change in.

I will update my status on confirming this patch by Monday.

glassfishrobot commented 15 years ago

@glassfishrobot Commented @jfialli said: Patch checked in. Will be included in next shoal-integration into application server.

glassfishrobot commented 15 years ago

@glassfishrobot Commented File: DistributedStateCacheImpl-Diff.txt Attached By: okrische

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA SHOAL-79

glassfishrobot commented 14 years ago

@glassfishrobot Commented Marked as fixed on Wednesday, June 23rd 2010, 4:11:06 am