T
- the type of object in the poolpublic interface PooledObject<T> extends Comparable<PooledObject<T>>
Implementations of this class are required to be thread-safe.
Modifier and Type | Method and Description |
---|---|
boolean |
allocate()
Allocates the object.
|
int |
compareTo(PooledObject<T> other)
Orders instances based on idle time - i.e.
|
boolean |
deallocate()
|
boolean |
endEvictionTest(Deque<PooledObject<T>> idleQueue)
Notifies the object that the eviction test has ended.
|
boolean |
equals(Object obj) |
default Duration |
getActiveDuration()
Gets the amount of time this object last spent in the active state (it may still be active in which case
subsequent calls will return an increased value).
|
default Duration |
getActiveTime()
Deprecated.
Use
getActiveDuration() . |
long |
getActiveTimeMillis()
Deprecated.
Use
getActiveTime() which offers the best precision. |
default long |
getBorrowedCount()
Gets the number of times this object has been borrowed.
|
default Instant |
getCreateInstant()
Gets the time (using the same basis as
Instant.now() ) that this object was created. |
long |
getCreateTime()
Deprecated.
Use
getCreateInstant() which offers the best precision. |
default Duration |
getIdleDuration()
Gets the amount of time that this object last spend in the
idle state (it may still be idle in which case subsequent calls will
return an increased value).
|
default Duration |
getIdleTime()
Deprecated.
Use
getIdleDuration() . |
long |
getIdleTimeMillis()
Deprecated.
Use
getIdleTime() which offers the best precision. |
default Instant |
getLastBorrowInstant()
Gets the time the wrapped object was last borrowed.
|
long |
getLastBorrowTime()
Deprecated.
Use
getLastBorrowInstant() which offers the best precision. |
default Instant |
getLastReturnInstant()
Gets the time the wrapped object was last borrowed.
|
long |
getLastReturnTime()
Deprecated.
Use
getLastReturnInstant() which offers the best precision. |
default Instant |
getLastUsedInstant()
Gets an estimate of the last time this object was used.
|
long |
getLastUsedTime()
Deprecated.
Use
getLastUsedInstant() which offers the best precision. |
T |
getObject()
Gets the underlying object that is wrapped by this instance of
PooledObject . |
PooledObjectState |
getState()
Gets the state of this object.
|
int |
hashCode() |
void |
invalidate()
Sets the state to
INVALID . |
void |
markAbandoned()
Marks the pooled object as abandoned.
|
void |
markReturning()
Marks the object as returning to the pool.
|
void |
printStackTrace(PrintWriter writer)
Prints the stack trace of the code that borrowed this pooled object and
the stack trace of the last code to use this object (if available) to
the supplied writer.
|
void |
setLogAbandoned(boolean logAbandoned)
Sets whether to use abandoned object tracking.
|
default void |
setRequireFullStackTrace(boolean requireFullStackTrace)
Sets the stack trace generation strategy based on whether or not fully detailed stack traces are required.
|
boolean |
startEvictionTest()
Attempts to place the pooled object in the
PooledObjectState.EVICTION state. |
String |
toString()
Gets a String form of the wrapper for debug purposes.
|
void |
use()
Records the current stack trace as the last time the object was used.
|
boolean allocate()
true
if the original state was IDLE
int compareTo(PooledObject<T> other)
Note: This class has a natural ordering that is inconsistent with equals if distinct objects have the same identity hash code.
compareTo
in interface Comparable<PooledObject<T>>
boolean deallocate()
true
if the state was ALLOCATED
.boolean endEvictionTest(Deque<PooledObject<T>> idleQueue)
idleQueue
- The queue of idle objects to which the object should be
returned.default Duration getActiveDuration()
@Deprecated default Duration getActiveTime()
getActiveDuration()
.@Deprecated long getActiveTimeMillis()
getActiveTime()
which offers the best precision.default long getBorrowedCount()
default Instant getCreateInstant()
Instant.now()
) that this object was created.@Deprecated long getCreateTime()
getCreateInstant()
which offers the best precision.System.currentTimeMillis()
) that this object was created.default Duration getIdleDuration()
@Deprecated default Duration getIdleTime()
getIdleDuration()
.@Deprecated long getIdleTimeMillis()
getIdleTime()
which offers the best precision.default Instant getLastBorrowInstant()
@Deprecated long getLastBorrowTime()
getLastBorrowInstant()
which offers the best precision.default Instant getLastReturnInstant()
@Deprecated long getLastReturnTime()
getLastReturnInstant()
which offers the best precision.default Instant getLastUsedInstant()
TrackedUse
, what is returned is the maximum of TrackedUse.getLastUsedInstant()
and
getLastBorrowTime()
; otherwise this method gives the same value as getLastBorrowTime()
.@Deprecated long getLastUsedTime()
getLastUsedInstant()
which offers the best precision.TrackedUse
, what is returned is
the maximum of TrackedUse.getLastUsedInstant()
and
getLastBorrowTime()
; otherwise this method gives the same
value as getLastBorrowTime()
.T getObject()
PooledObject
.PooledObjectState getState()
void invalidate()
INVALID
.void markAbandoned()
void markReturning()
void printStackTrace(PrintWriter writer)
writer
- The destination for the debug output.void setLogAbandoned(boolean logAbandoned)
logAbandoned
- The new configuration setting for abandoned
object tracking.default void setRequireFullStackTrace(boolean requireFullStackTrace)
requireFullStackTrace
- the new configuration setting for abandoned object logging.boolean startEvictionTest()
PooledObjectState.EVICTION
state.true
if the object was placed in the
PooledObjectState.EVICTION
state otherwise
false
.String toString()
void use()
Copyright © 2001–2021 The Apache Software Foundation. All rights reserved.