Skip to content

com.google.common.cache.AbstractCache.SimpleStatsCounter is NOT thread-safe #2230

@mkramanathan

Description

@mkramanathan

While using the SimpleStatsCounter class in the com.google.common.cache package, we found that it is not thread-safe as documented. As a simple example, we can have one thread invoking recordLoadSuccess with a non-zero value. It executes loadSuccessCount.increment() and before it can execute totalLoadTime.add(loadTime), if another threads calls a snapshot on the cache, it will return an inconsistent state (where the successCount and loadtime are inconsistent).

Should the methods be synchronized in this class? If not, may be the documentation can be fixed to remove claims on thread-safety?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions