Package org.apache.tomcat.dbcp.pool2
Interface PooledObject<T>
- Type Parameters:
- T- the type of object in the pool.
- All Superinterfaces:
- Comparable<PooledObject<T>>
- All Known Implementing Classes:
- DefaultPooledObject,- PooledSoftReference
Defines the wrapper that is used to track the additional information, such as
 state, for the pooled objects.
 
Implementations of this class are required to be thread-safe.
- Since:
- 2.0
- 
Method SummaryModifier and TypeMethodDescriptionbooleanallocate()Allocates the object.intcompareTo(PooledObject<T> other) Orders instances based on idle time - i.e. the length of time since the instance was returned to the pool.booleanbooleanendEvictionTest(Deque<PooledObject<T>> idleQueue) Notifies the object that the eviction test has ended.booleandefault DurationGets 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 DurationDeprecated.longDeprecated.UsegetActiveTime()which offers the best precision.default longGets the number of times this object has been borrowed.default InstantGets the time (using the same basis asInstant.now()) that this object was created.longDeprecated.UsegetCreateInstant()which offers the best precision.default DurationGets the duration since this object was created (usingInstant.now()).default DurationGets 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 DurationDeprecated.UsegetIdleDuration().longDeprecated.UsegetIdleTime()which offers the best precision.default InstantGets the time the wrapped object was last borrowed.longDeprecated.UsegetLastBorrowInstant()which offers the best precision.default InstantGets the time the wrapped object was last borrowed.longDeprecated.UsegetLastReturnInstant()which offers the best precision.default InstantGets an estimate of the last time this object was used.longDeprecated.UsegetLastUsedInstant()which offers the best precision.Gets the underlying object that is wrapped by this instance ofPooledObject.getState()Gets the state of this object.inthashCode()voidSets the state toINVALID.static booleanisNull(PooledObject<?> pooledObject) Tests whether the given PooledObject is null or contains a null.voidMarks the pooled object as abandoned.voidMarks the object as returning to the pool.voidprintStackTrace(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.voidsetLogAbandoned(boolean logAbandoned) Sets whether to use abandoned object tracking.default voidsetRequireFullStackTrace(boolean requireFullStackTrace) Sets the stack trace generation strategy based on whether or not fully detailed stack traces are required.booleanAttempts to place the pooled object in thePooledObjectState.EVICTIONstate.toString()Gets a String form of the wrapper for debug purposes.voiduse()Records the current stack trace as the last time the object was used.
- 
Method Details- 
isNullTests whether the given PooledObject is null or contains a null.- Parameters:
- pooledObject- the PooledObject to test.
- Returns:
- whether the given PooledObject is null or contains a null.
- Since:
- 2.12.0
 
- 
allocateboolean allocate()Allocates the object.- Returns:
- trueif the original state was- IDLE
 
- 
compareToOrders instances based on idle time - i.e. the length of time since the instance was returned to the pool. Used by the GKOP idle object evictor.Note: This class has a natural ordering that is inconsistent with equals if distinct objects have the same identity hash code. - Specified by:
- compareToin interface- Comparable<T>
 
- 
deallocateboolean deallocate()- Returns:
- trueif the state was- ALLOCATED.
 
- 
endEvictionTestNotifies the object that the eviction test has ended.- Parameters:
- idleQueue- The queue of idle objects to which the object should be returned.
- Returns:
- Currently not used.
 
- 
equals
- 
getActiveDurationGets 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).- Returns:
- The duration last spent in the active state.
- Since:
- 2.11.0
 
- 
getActiveTimeDeprecated.UsegetActiveDuration().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).- Returns:
- The duration last spent in the active state.
- Since:
- 2.10.0
 
- 
getActiveTimeMillisDeprecated.UsegetActiveTime()which offers the best precision.Gets the amount of time in milliseconds this object last spent in the active state (it may still be active in which case subsequent calls will return an increased value).- Returns:
- The time in milliseconds last spent in the active state.
 
- 
getBorrowedCountdefault long getBorrowedCount()Gets the number of times this object has been borrowed.- Returns:
- -1 by default for implementations prior to release 2.7.0.
- Since:
- 2.7.0
 
- 
getCreateInstantGets the time (using the same basis asInstant.now()) that this object was created.- Returns:
- The creation time for the wrapped object.
- Since:
- 2.11.0
 
- 
getCreateTimeDeprecated.UsegetCreateInstant()which offers the best precision.Gets the time (using the same basis asClock.instant()) that this object was created.- Returns:
- The creation time for the wrapped object.
 
- 
getFullDurationGets the duration since this object was created (usingInstant.now()).- Returns:
- The duration since this object was created.
- Since:
- 2.12.0
 
- 
getIdleDurationGets 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).- Returns:
- The amount of time in last spent in the idle state.
- Since:
- 2.11.0
 
- 
getIdleTimeDeprecated.UsegetIdleDuration().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).- Returns:
- The amount of time in last spent in the idle state.
- Since:
- 2.10.0
 
- 
getIdleTimeMillisDeprecated.UsegetIdleTime()which offers the best precision.Gets the amount of time in milliseconds that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).- Returns:
- The time in milliseconds last spent in the idle state.
 
- 
getLastBorrowInstantGets the time the wrapped object was last borrowed.- Returns:
- The time the object was last borrowed.
- Since:
- 2.11.0
 
- 
getLastBorrowTimeDeprecated.UsegetLastBorrowInstant()which offers the best precision.Gets the time the wrapped object was last borrowed.- Returns:
- The time the object was last borrowed.
 
- 
getLastReturnInstantGets the time the wrapped object was last borrowed.- Returns:
- The time the object was last borrowed.
- Since:
- 2.11.0
 
- 
getLastReturnTimeDeprecated.UsegetLastReturnInstant()which offers the best precision.Gets the time the wrapped object was last returned.- Returns:
- The time the object was last returned.
 
- 
getLastUsedInstantGets an estimate of the last time this object was used. If the class of the pooled object implementsTrackedUse, what is returned is the maximum ofTrackedUse.getLastUsedInstant()andgetLastBorrowTime(); otherwise this method gives the same value asgetLastBorrowTime().- Returns:
- the last time this object was used
- Since:
- 2.11.0
 
- 
getLastUsedTimeDeprecated.UsegetLastUsedInstant()which offers the best precision.Gets an estimate of the last time this object was used. If the class of the pooled object implementsTrackedUse, what is returned is the maximum ofTrackedUse.getLastUsedInstant()andgetLastBorrowTime(); otherwise this method gives the same value asgetLastBorrowTime().- Returns:
- the last time this object was used.
 
- 
getObjectT getObject()Gets the underlying object that is wrapped by this instance ofPooledObject.- Returns:
- The wrapped object.
 
- 
getStatePooledObjectState getState()Gets the state of this object.- Returns:
- state
 
- 
hashCodeint hashCode()
- 
invalidatevoid invalidate()Sets the state toINVALID.
- 
markAbandonedvoid markAbandoned()Marks the pooled object as abandoned.
- 
markReturningvoid markReturning()Marks the object as returning to the pool.
- 
printStackTracePrints 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.- Parameters:
- writer- The destination for the debug output.
 
- 
setLogAbandonedvoid setLogAbandoned(boolean logAbandoned) Sets whether to use abandoned object tracking. If this is true the implementation will need to record the stack trace of the last caller to borrow this object.- Parameters:
- logAbandoned- The new configuration setting for abandoned object tracking.
 
- 
setRequireFullStackTracedefault void setRequireFullStackTrace(boolean requireFullStackTrace) Sets the stack trace generation strategy based on whether or not fully detailed stack traces are required. When set to false, abandoned logs may only include caller class information rather than method names, line numbers, and other normal metadata available in a full stack trace.- Parameters:
- requireFullStackTrace- the new configuration setting for abandoned object logging.
- Since:
- 2.7.0
 
- 
startEvictionTestboolean startEvictionTest()Attempts to place the pooled object in thePooledObjectState.EVICTIONstate.- Returns:
- trueif the object was placed in the- PooledObjectState.EVICTIONstate otherwise- false.
 
- 
toStringString toString()Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.
- 
usevoid use()Records the current stack trace as the last time the object was used.
 
- 
getActiveDuration().