Package org.apache.tomcat.dbcp.pool2
Interface PooledObject<T>
- 
- Type Parameters:
- T- the type of object in the pool
 - All Superinterfaces:
- java.lang.Comparable<PooledObject<T>>
 - All Known Implementing Classes:
- DefaultPooledObject,- PooledSoftReference
 
 public interface PooledObject<T> extends java.lang.Comparable<PooledObject<T>> 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 SummaryAll Methods Instance Methods Abstract 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)Called to inform the object that the eviction test has ended.booleanequals(java.lang.Object obj)longgetActiveTimeMillis()Obtains the time in milliseconds that 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.longgetCreateTime()Obtains the time (using the same basis asSystem.currentTimeMillis()) that this object was created.longgetIdleTimeMillis()Obtains the 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).longgetLastBorrowTime()Obtains the time the wrapped object was last borrowed.longgetLastReturnTime()Obtains the time the wrapped object was last returned.longgetLastUsedTime()Returns an estimate of the last time this object was used.TgetObject()Obtains the underlying object that is wrapped by this instance ofPooledObject.PooledObjectStategetState()Returns the state of this object.inthashCode()voidinvalidate()Sets the state toINVALIDvoidmarkAbandoned()Marks the pooled object as abandoned.voidmarkReturning()Marks the object as returning to the pool.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)Is abandoned object tracking being used?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()Provides a String form of the wrapper for debug purposes.voiduse()Record the current stack trace as the last time the object was used.
 
- 
- 
- 
Method Detail- 
getObjectT getObject() Obtains the underlying object that is wrapped by this instance ofPooledObject.- Returns:
- The wrapped object
 
 - 
getCreateTimelong getCreateTime() Obtains the time (using the same basis asSystem.currentTimeMillis()) that this object was created.- Returns:
- The creation time for the wrapped object
 
 - 
getActiveTimeMillislong getActiveTimeMillis() Obtains the time in milliseconds that 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
 
 - 
getBorrowedCountlong getBorrowedCount() Gets the number of times this object has been borrowed.- Returns:
- The number of times this object has been borrowed.
- Since:
- 2.7.0
 
 - 
getIdleTimeMillislong getIdleTimeMillis() Obtains the 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
 
 - 
getLastBorrowTimelong getLastBorrowTime() Obtains the time the wrapped object was last borrowed.- Returns:
- The time the object was last borrowed
 
 - 
getLastReturnTimelong getLastReturnTime() Obtains the time the wrapped object was last returned.- Returns:
- The time the object was last returned
 
 - 
getLastUsedTimelong getLastUsedTime() Returns 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.getLastUsed()andgetLastBorrowTime(); otherwise this method gives the same value asgetLastBorrowTime().- Returns:
- the last time this object was used
 
 - 
compareToint compareTo(PooledObject<T> other) Orders 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>
 
 - 
equalsboolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
hashCodeint hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
toStringjava.lang.String toString() Provides a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.- Overrides:
- toStringin class- java.lang.Object
 
 - 
startEvictionTestboolean startEvictionTest() Attempts to place the pooled object in thePooledObjectState.EVICTIONstate.- Returns:
- trueif the object was placed in the- PooledObjectState.EVICTIONstate otherwise- false
 
 - 
endEvictionTestboolean endEvictionTest(java.util.Deque<PooledObject<T>> idleQueue) Called to inform 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
 
 - 
allocateboolean allocate() Allocates the object.- Returns:
- trueif the original state was- IDLE
 
 - 
deallocateboolean deallocate() - Returns:
- trueif the state was- ALLOCATED
 
 - 
invalidatevoid invalidate() Sets the state toINVALID
 - 
setLogAbandonedvoid setLogAbandoned(boolean logAbandoned) Is abandoned object tracking being used? 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
 
 - 
setRequireFullStackTracevoid 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.- Parameters:
- requireFullStackTrace- the new configuration setting for abandoned object logging
- Since:
- 2.7.0
 
 - 
usevoid use() Record the current stack trace as the last time the object was used.
 - 
printStackTracevoid printStackTrace(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.- Parameters:
- writer- The destination for the debug output
 
 - 
getStatePooledObjectState getState() Returns the state of this object.- Returns:
- state
 
 - 
markAbandonedvoid markAbandoned() Marks the pooled object as abandoned.
 - 
markReturningvoid markReturning() Marks the object as returning to the pool.
 
- 
 
-