Top Description Methods
org.apache.commons.pool2

public Interface PooledObject<T>

extends Comparable<PooledObject<T>>
Known Direct Implementers
org.apache.commons.pool2.impl.DefaultPooledObject
Type Parameters
<T>
the type of object in the pool.
Imports
java.io.PrintWriter, java.time.Duration, .Instant, java.util.Deque

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 Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the original state was IDLE
allocate
()

Allocates the object.

public int
compareTo(PooledObject<T>
the object to be compared.
other
)

Redeclares java.lang.Comparable.compareTo.

Orders instances based on idle time - i.e. the length of time since the instance was returned to the pool.
public boolean

Returns:

true if the state was ALLOCATED.
deallocate
()

Deallocates the object and sets it IDLE if it is currently ALLOCATED.

public boolean

Returns:

Currently not used.
endEvictionTest
(Deque<PooledObject<T>>
The queue of idle objects to which the object should be returned.
idleQueue
)

Notifies the object that the eviction test has ended.

public boolean
public default Duration

Returns:

The duration last spent in the active state.
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).

public default Duration

Returns:

The duration last spent in the active state.
getActiveTime
()

Deprecated Use 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).
public long

Returns:

The time in milliseconds last spent in the active state.
getActiveTimeMillis
()

Deprecated Use getActiveTime() 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).
public default long

Returns:

-1 by default for implementations prior to release 2.7.0.
getBorrowedCount
()

Gets the number of times this object has been borrowed.

public default Instant

Returns:

The creation time for the wrapped object.
getCreateInstant
()

Gets the time (using the same basis as Instant#now()) that this object was created.

public long

Returns:

The creation time for the wrapped object.
getCreateTime
()

Deprecated Use getCreateInstant() which offers the best precision.
Gets the time (using the same basis as java.time.Clock#instant()) that this object was created.
public default Duration

Returns:

The duration since this object was created.
getFullDuration
()

Gets the duration since this object was created (using Instant#now()).

public default Duration

Returns:

The amount of time in last spent in the idle state.
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).

public default Duration

Returns:

The amount of time in last spent in the idle state.
getIdleTime
()

Deprecated Use 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).
public long

Returns:

The time in milliseconds last spent in the idle state.
getIdleTimeMillis
()

Deprecated Use getIdleTime() 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).
public default Instant

Returns:

The time the object was last borrowed.
getLastBorrowInstant
()

Gets the time the wrapped object was last borrowed.

public long

Returns:

The time the object was last borrowed.
getLastBorrowTime
()

Deprecated Use getLastBorrowInstant() which offers the best precision.
Gets the time the wrapped object was last borrowed.
public default Instant

Returns:

The time the object was last borrowed.
getLastReturnInstant
()

Gets the time the wrapped object was last borrowed.

public long

Returns:

The time the object was last returned.
getLastReturnTime
()

Deprecated Use getLastReturnInstant() which offers the best precision.
Gets the time the wrapped object was last returned.
public default Instant

Returns:

the last time this object was used
getLastUsedInstant
()

Gets an estimate of the last time this object was used.

public long

Returns:

the last time this object was used.
getLastUsedTime
()

Deprecated Use getLastUsedInstant() which offers the best precision.
Gets an estimate of the last time this object was used.
public T

Returns:

The wrapped object.
getObject
()

Gets the underlying object that is wrapped by this instance of PooledObject.

public PooledObjectState

Returns:

state
getState
()

Gets the state of this object.

public int
public void
invalidate()

Sets the state to INVALID.

public static boolean

Returns:

whether the given PooledObject is null or contains a null.
isNull
(final PooledObject<?>
the PooledObject to test.
pooledObject
)

Tests whether the given PooledObject is null or contains a null.

public void
markAbandoned()

Marks the pooled object as abandoned.

public void
markReturning()

Marks the object as returning to the pool.

public void
printStackTrace(PrintWriter
The destination for the debug output.
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.

public void
setLogAbandoned(boolean
The new configuration setting for abandoned object tracking.
logAbandoned
)

Sets whether to use abandoned object tracking.

public default void
setRequireFullStackTrace(final boolean
the new configuration setting for abandoned object logging.
requireFullStackTrace
)

Sets the stack trace generation strategy based on whether or not fully detailed stack traces are required.

public boolean

Returns:

true if the object was placed in the PooledObjectState#EVICTION state otherwise false.
startEvictionTest
()

Attempts to place the pooled object in the PooledObjectState#EVICTION state.

public String
toString()

Gets a String form of the wrapper for debug purposes.

public void
use()

Records the current stack trace as the last time the object was used.

Method Detail

allocateback to summary
public boolean allocate()

Allocates the object.

Returns:boolean

true if the original state was IDLE

compareToback to summary
public int compareTo(PooledObject<T> other)

Redeclares java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

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.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:PooledObject<T>

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
deallocateback to summary
public boolean deallocate()

Deallocates the object and sets it IDLE if it is currently ALLOCATED.

Returns:boolean

true if the state was ALLOCATED.

endEvictionTestback to summary
public boolean endEvictionTest(Deque<PooledObject<T>> idleQueue)

Notifies the object that the eviction test has ended.

Parameters
idleQueue:Deque<PooledObject<T>>

The queue of idle objects to which the object should be returned.

Returns:boolean

Currently not used.

equalsback to summary
public boolean equals(Object obj)
Annotations
@Override
getActiveDurationback to summary
public 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).

Returns:Duration

The duration last spent in the active state.

Since
2.11.0
getActiveTimeback to summary
public default Duration getActiveTime()

Deprecated

Use 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).

Returns:Duration

The duration last spent in the active state.

Annotations
@Deprecated
Since
2.10.0
getActiveTimeMillisback to summary
public long getActiveTimeMillis()

Deprecated

Use getActiveTime() 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:long

The time in milliseconds last spent in the active state.

Annotations
@Deprecated
getBorrowedCountback to summary
public default long getBorrowedCount()

Gets the number of times this object has been borrowed.

Returns:long

-1 by default for implementations prior to release 2.7.0.

Since
2.7.0
getCreateInstantback to summary
public default Instant getCreateInstant()

Gets the time (using the same basis as Instant#now()) that this object was created.

Returns:Instant

The creation time for the wrapped object.

Since
2.11.0
getCreateTimeback to summary
public long getCreateTime()

Deprecated

Use getCreateInstant() which offers the best precision.

Gets the time (using the same basis as java.time.Clock#instant()) that this object was created.

Returns:long

The creation time for the wrapped object.

Annotations
@Deprecated
getFullDurationback to summary
public default Duration getFullDuration()

Gets the duration since this object was created (using Instant#now()).

Returns:Duration

The duration since this object was created.

Since
2.12.0
getIdleDurationback to summary
public 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).

Returns:Duration

The amount of time in last spent in the idle state.

Since
2.11.0
getIdleTimeback to summary
public default Duration getIdleTime()

Deprecated

Use 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).

Returns:Duration

The amount of time in last spent in the idle state.

Annotations
@Deprecated
Since
2.10.0
getIdleTimeMillisback to summary
public long getIdleTimeMillis()

Deprecated

Use getIdleTime() 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:long

The time in milliseconds last spent in the idle state.

Annotations
@Deprecated
getLastBorrowInstantback to summary
public default Instant getLastBorrowInstant()

Gets the time the wrapped object was last borrowed.

Returns:Instant

The time the object was last borrowed.

Since
2.11.0
getLastBorrowTimeback to summary
public long getLastBorrowTime()

Deprecated

Use getLastBorrowInstant() which offers the best precision.

Gets the time the wrapped object was last borrowed.

Returns:long

The time the object was last borrowed.

Annotations
@Deprecated
getLastReturnInstantback to summary
public default Instant getLastReturnInstant()

Gets the time the wrapped object was last borrowed.

Returns:Instant

The time the object was last borrowed.

Since
2.11.0
getLastReturnTimeback to summary
public long getLastReturnTime()

Deprecated

Use getLastReturnInstant() which offers the best precision.

Gets the time the wrapped object was last returned.

Returns:long

The time the object was last returned.

Annotations
@Deprecated
getLastUsedInstantback to summary
public default Instant getLastUsedInstant()

Gets an estimate of the last time this object was used. If the class of the pooled object implements TrackedUse, what is returned is the maximum of TrackedUse#getLastUsedInstant() and getLastBorrowTime(); otherwise this method gives the same value as getLastBorrowTime().

Returns:Instant

the last time this object was used

Since
2.11.0
getLastUsedTimeback to summary
public long getLastUsedTime()

Deprecated

Use getLastUsedInstant() which offers the best precision.

Gets an estimate of the last time this object was used. If the class of the pooled object implements TrackedUse, what is returned is the maximum of TrackedUse#getLastUsedInstant() and getLastBorrowTime(); otherwise this method gives the same value as getLastBorrowTime().

Returns:long

the last time this object was used.

Annotations
@Deprecated
getObjectback to summary
public T getObject()

Gets the underlying object that is wrapped by this instance of PooledObject.

Returns:T

The wrapped object.

getStateback to summary
public PooledObjectState getState()

Gets the state of this object.

Returns:PooledObjectState

state

hashCodeback to summary
public int hashCode()
Annotations
@Override
invalidateback to summary
public void invalidate()

Sets the state to INVALID.

isNullback to summary
public static boolean isNull(final PooledObject<?> pooledObject)

Tests whether the given PooledObject is null or contains a null.

Parameters
pooledObject:PooledObject<?>

the PooledObject to test.

Returns:boolean

whether the given PooledObject is null or contains a null.

Since
2.12.0
markAbandonedback to summary
public void markAbandoned()

Marks the pooled object as abandoned.

markReturningback to summary
public void markReturning()

Marks the object as returning to the pool.

printStackTraceback to summary
public 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.

Parameters
writer:PrintWriter

The destination for the debug output.

setLogAbandonedback to summary
public void 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:boolean

The new configuration setting for abandoned object tracking.

setRequireFullStackTraceback to summary
public default void setRequireFullStackTrace(final 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:boolean

the new configuration setting for abandoned object logging.

Since
2.7.0
startEvictionTestback to summary
public boolean startEvictionTest()

Attempts to place the pooled object in the PooledObjectState#EVICTION state.

Returns:boolean

true if the object was placed in the PooledObjectState#EVICTION state otherwise false.

toStringback to summary
public String toString()

Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.

Annotations
@Override
useback to summary
public void use()

Records the current stack trace as the last time the object was used.