Class DefaultPooledObject<T>
- java.lang.Object
- 
- org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject<T>
 
- 
- Type Parameters:
- T- the type of object in the pool
 - All Implemented Interfaces:
- java.lang.Comparable<PooledObject<T>>,- PooledObject<T>
 - Direct Known Subclasses:
- PooledSoftReference
 
 public class DefaultPooledObject<T> extends java.lang.Object implements PooledObject<T> This wrapper is used to track the additional information, such as state, for the pooled objects.This class is intended to be thread-safe. - Since:
- 2.0
 
- 
- 
Constructor SummaryConstructors Constructor Description DefaultPooledObject(T object)Creates a new instance that wraps the provided object so that the pool can track the state of the pooled object.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallocate()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.booleandeallocate()booleanendEvictionTest(java.util.Deque<PooledObject<T>> idleQueue)Notifies the object that the eviction test has ended.longgetActiveTimeMillis()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).longgetBorrowedCount()Gets the number of times this object has been borrowed.java.time.InstantgetCreateInstant()Gets the time (using the same basis asInstant.now()) that this object was created.longgetCreateTime()Gets the time (using the same basis asSystem.currentTimeMillis()) that this object was created.java.time.DurationgetIdleDuration()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).java.time.DurationgetIdleTime()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).longgetIdleTimeMillis()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).java.time.InstantgetLastBorrowInstant()Gets the time the wrapped object was last borrowed.longgetLastBorrowTime()Gets the time the wrapped object was last borrowed.java.time.InstantgetLastReturnInstant()Gets the time the wrapped object was last borrowed.longgetLastReturnTime()Gets the time the wrapped object was last returned.java.time.InstantgetLastUsedInstant()Gets an estimate of the last time this object was used.longgetLastUsedTime()Gets an estimate of the last time this object was used.TgetObject()Gets the underlying object that is wrapped by this instance ofPooledObject.PooledObjectStategetState()Gets the state of this object.voidinvalidate()Sets the state toINVALID.voidmarkAbandoned()Marks the pooled object asABANDONED.voidmarkReturning()Marks the pooled object asRETURNING.voidprintStackTrace(java.io.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.voidsetRequireFullStackTrace(boolean requireFullStackTrace)Configures the stack trace generation strategy based on whether or not fully detailed stack traces are required.booleanstartEvictionTest()Attempts to place the pooled object in thePooledObjectState.EVICTIONstate.java.lang.StringtoString()Gets a String form of the wrapper for debug purposes.voiduse()Records the current stack trace as the last time the object was used.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.tomcat.dbcp.pool2.PooledObjectequals, getActiveDuration, getActiveTime, getFullDuration, hashCode
 
- 
 
- 
- 
- 
Constructor Detail- 
DefaultPooledObjectpublic DefaultPooledObject(T object) Creates a new instance that wraps the provided object so that the pool can track the state of the pooled object.- Parameters:
- object- The object to wrap
 
 
- 
 - 
Method Detail- 
allocatepublic boolean allocate() Allocates the object.- Specified by:
- allocatein interface- PooledObject<T>
- Returns:
- trueif the original state was- IDLE
 
 - 
compareTopublic int compareTo(PooledObject<T> other) Description copied from interface:PooledObjectOrders 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- java.lang.Comparable<T>
- Specified by:
- compareToin interface- PooledObject<T>
 
 - 
deallocatepublic boolean deallocate() - Specified by:
- deallocatein interface- PooledObject<T>
- Returns:
- trueif the state was- ALLOCATEDor- RETURNING.
 
 - 
endEvictionTestpublic boolean endEvictionTest(java.util.Deque<PooledObject<T>> idleQueue) Description copied from interface:PooledObjectNotifies the object that the eviction test has ended.- Specified by:
- endEvictionTestin interface- PooledObject<T>
- Parameters:
- idleQueue- The queue of idle objects to which the object should be returned.
- Returns:
- Currently not used.
 
 - 
getActiveTimeMillispublic long getActiveTimeMillis() Description copied from interface:PooledObjectGets 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).- Specified by:
- getActiveTimeMillisin interface- PooledObject<T>
- Returns:
- The time in milliseconds last spent in the active state.
 
 - 
getBorrowedCountpublic long getBorrowedCount() Gets the number of times this object has been borrowed.- Specified by:
- getBorrowedCountin interface- PooledObject<T>
- Returns:
- The number of times this object has been borrowed.
- Since:
- 2.1
 
 - 
getCreateInstantpublic java.time.Instant getCreateInstant() Description copied from interface:PooledObjectGets the time (using the same basis asInstant.now()) that this object was created.- Specified by:
- getCreateInstantin interface- PooledObject<T>
- Returns:
- The creation time for the wrapped object.
 
 - 
getCreateTimepublic long getCreateTime() Description copied from interface:PooledObjectGets the time (using the same basis asSystem.currentTimeMillis()) that this object was created.- Specified by:
- getCreateTimein interface- PooledObject<T>
- Returns:
- The creation time for the wrapped object.
 
 - 
getIdleDurationpublic java.time.Duration getIdleDuration() Description copied from interface:PooledObjectGets 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).- Specified by:
- getIdleDurationin interface- PooledObject<T>
- Returns:
- The amount of time in last spent in the idle state.
 
 - 
getIdleTimepublic java.time.Duration getIdleTime() Description copied from interface:PooledObjectGets 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).- Specified by:
- getIdleTimein interface- PooledObject<T>
- Returns:
- The amount of time in last spent in the idle state.
 
 - 
getIdleTimeMillispublic long getIdleTimeMillis() Description copied from interface:PooledObjectGets 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).- Specified by:
- getIdleTimeMillisin interface- PooledObject<T>
- Returns:
- The time in milliseconds last spent in the idle state.
 
 - 
getLastBorrowInstantpublic java.time.Instant getLastBorrowInstant() Description copied from interface:PooledObjectGets the time the wrapped object was last borrowed.- Specified by:
- getLastBorrowInstantin interface- PooledObject<T>
- Returns:
- The time the object was last borrowed.
 
 - 
getLastBorrowTimepublic long getLastBorrowTime() Description copied from interface:PooledObjectGets the time the wrapped object was last borrowed.- Specified by:
- getLastBorrowTimein interface- PooledObject<T>
- Returns:
- The time the object was last borrowed.
 
 - 
getLastReturnInstantpublic java.time.Instant getLastReturnInstant() Description copied from interface:PooledObjectGets the time the wrapped object was last borrowed.- Specified by:
- getLastReturnInstantin interface- PooledObject<T>
- Returns:
- The time the object was last borrowed.
 
 - 
getLastReturnTimepublic long getLastReturnTime() Description copied from interface:PooledObjectGets the time the wrapped object was last returned.- Specified by:
- getLastReturnTimein interface- PooledObject<T>
- Returns:
- The time the object was last returned.
 
 - 
getLastUsedInstantpublic java.time.Instant getLastUsedInstant() 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().- Specified by:
- getLastUsedInstantin interface- PooledObject<T>
- Returns:
- the last Instant this object was used.
 
 - 
getLastUsedTimepublic long getLastUsedTime() 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().- Specified by:
- getLastUsedTimein interface- PooledObject<T>
- Returns:
- the last time this object was used
 
 - 
getObjectpublic T getObject() Description copied from interface:PooledObjectGets the underlying object that is wrapped by this instance ofPooledObject.- Specified by:
- getObjectin interface- PooledObject<T>
- Returns:
- The wrapped object.
 
 - 
getStatepublic PooledObjectState getState() Gets the state of this object.- Specified by:
- getStatein interface- PooledObject<T>
- Returns:
- state
 
 - 
invalidatepublic void invalidate() Sets the state toINVALID.- Specified by:
- invalidatein interface- PooledObject<T>
 
 - 
markAbandonedpublic void markAbandoned() Marks the pooled object asABANDONED.- Specified by:
- markAbandonedin interface- PooledObject<T>
 
 - 
markReturningpublic void markReturning() Marks the pooled object asRETURNING.- Specified by:
- markReturningin interface- PooledObject<T>
 
 - 
printStackTracepublic void printStackTrace(java.io.PrintWriter writer) Description copied from interface:PooledObjectPrints 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.- Specified by:
- printStackTracein interface- PooledObject<T>
- Parameters:
- writer- The destination for the debug output.
 
 - 
setLogAbandonedpublic void setLogAbandoned(boolean logAbandoned) Description copied from interface:PooledObjectSets 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.- Specified by:
- setLogAbandonedin interface- PooledObject<T>
- Parameters:
- logAbandoned- The new configuration setting for abandoned object tracking.
 
 - 
setRequireFullStackTracepublic void setRequireFullStackTrace(boolean requireFullStackTrace) Configures 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.- Specified by:
- setRequireFullStackTracein interface- PooledObject<T>
- Parameters:
- requireFullStackTrace- the new configuration setting for abandoned object logging
- Since:
- 2.5
 
 - 
startEvictionTestpublic boolean startEvictionTest() Description copied from interface:PooledObjectAttempts to place the pooled object in thePooledObjectState.EVICTIONstate.- Specified by:
- startEvictionTestin interface- PooledObject<T>
- Returns:
- trueif the object was placed in the- PooledObjectState.EVICTIONstate otherwise- false.
 
 - 
toStringpublic java.lang.String toString() Description copied from interface:PooledObjectGets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.- Specified by:
- toStringin interface- PooledObject<T>
- Overrides:
- toStringin class- java.lang.Object
 
 - 
usepublic void use() Description copied from interface:PooledObjectRecords the current stack trace as the last time the object was used.- Specified by:
- usein interface- PooledObject<T>
 
 
- 
 
-