Add a PriorityQueue
-for-idle-resources variant
#88
Labels
for/user-attention
This issue needs user attention (feedback, rework, etc...)
status/need-investigation
This needs more in-depth investigation
type/enhancement
A general enhancement
Milestone
Motivation
An extension of #87 where other criteria than Least|Most-Recently-Used would be possible for polling order of idle resources (ie. created oldest).
The Priority Queue opens up more usages since a
Comparator<PooledRef>
can be used. For instance, one could prioritize youngest/oldest resources (in terms of creation time, independently of when it was last released) or by number of acquisitions. As long as the "priority" is not changing after insertion.This implies:
PooledRef
release timestamp (and creation timestamp): as "age" is a function of time and so is too dynamic for a priority => a timestamp is more absolutePriorityQueue
interface relying onComparator
, implementations may be less efficient than simple baked-in fifo/lifo inDeque
implementationsAt the same time, it would better support maintaining order when polling-and-reinserting, which could help recover from some CAS failures.
Desired solution
An efficient Priority Queue implementation would be necessary, but the JDK only provides a binary-heap implementation that is not thread-safe (
PriorityQueue
) or a thread safe version that relies heavily on blocking/locks (PriorityBlockingQueue
).Considered alternatives
Implement one of the papers below.
Additional context
To our knowledge, no efficient lock-free implementation of Priority Queue exist in Java.
For reference, here are a few recent papers on concurrent priority queues:
The text was updated successfully, but these errors were encountered: