public interface SlotInfo<T extends Poolable>
An informative little interface, used by Expiration instances to
determine if a slot has expired or is still invalid for claiming.
| Modifier and Type | Method and Description |
|---|---|
long |
getAgeMillis()
Get the approximate number of milliseconds that have transpired since the
object was allocated.
|
long |
getClaimCount()
Get the number of times the object has been claimed since it was
allocated.
|
T |
getPoolable()
Get the Poolable object represented by this SlotInfo instance.
|
long |
getStamp()
Get the stamp value that has been set on this SlotInfo, or 0 if none has
been set since the Poolable was allocated.
|
int |
randomInt()
Produce a random int number.
|
void |
setStamp(long stamp)
Set the stamp value on this SlotInfo.
|
long getAgeMillis()
Get the approximate number of milliseconds that have transpired since the object was allocated.
long getClaimCount()
Get the number of times the object has been claimed since it was allocated.
T getPoolable()
Get the Poolable object represented by this SlotInfo instance.
|
Warning
|
Do not release()
Poolables from within an Expiration — doing so is a user
error, and the behaviour of the pool in such a situation is unspecified
and implementation specific. This means that dead-locks and infinite
loops are possible outcomes as well.
|
|
Warning
|
Also note that accessing the Poolable through
this method, from your Expiration implementation, is a
potentially concurrent access. This means that you need to take
thread-safety issues into consideration - especially if you intend on
manipulating the Poolable. In particular, you might be racing with other
threads that are checking if this Poolable is expired or not, and they
might even have claimed the Poolable and put it to use, by the time it
is returned from this method.
|
null.int randomInt()
Produce a random int number. This is useful for introducing spread, if the Expiration would otherwise have a tendency to cluster expirations close together in time, thereby causing the pool to suddenly have very few objects because of mass expirations.
Putting this method on SlotInfo might seem weird at first, but it allows the implementation to have very little contention. This is important on Java versions that don’t have ThreadLocalRandom.
long getStamp()
Get the stamp value that has been set on this SlotInfo, or 0 if none has been set since the Poolable was allocated.
Apart from the zero-value, the actual meaning of this value is completely
up to the Expiration that sets it.
void setStamp(long stamp)
Set the stamp value on this SlotInfo.
This method is only thread-safe to call from within the scope of the
Expiration.hasExpired(SlotInfo) method.
The stamp value is 0 by default, if it has not been set after the Poolable has been allocated. Its meaning is otherwise up to the particular Expiration that might use it.
stamp - The new stamp value.Copyright © 2011-2014–2015. All rights reserved.