Skip to content

Why ForkJoinPool.scan takes so many CPU #757

Answered by ben-manes
ministat asked this question in Q&A
Discussion options

You must be logged in to vote

The cache does not need FJP for its own operations and you can instead supply a caller-runs / direct executor, e.g. Runnable::run. That works fine for many users and our non-concurrent tests use that for simplicity.

An executor is used for any async code that may call a foreign (user supplied) method, since we won't know how expensive that is. For example during eviction a listener can be supplied for notification within the atomic map computation that removes the entry. The cache's own operations are fast and O(1), but users might do something unexpectedly expensive. If done on the calling thread then it could impact user-facing latencies, so the executor helps hide that.

Caffeine also o…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ministat
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants