PooledObject (Apache Commons Pool 2.5.0 API)

org.apache.commons.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

      public interface PooledObject<T>
      extends 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 Summary

    Methods
    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()` Deallocates the object and sets it `IDLE` if it is currently `ALLOCATED`.
    `boolean` | `endEvictionTest(Deque<PooledObject<T>> idleQueue)` Called to inform the object that the eviction test has ended.
    `boolean` | `equals(Object obj)`
    `long` | `getActiveTimeMillis()` Obtain 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).
    `long` | `getCreateTime()` Obtain the time (using the same basis as `System.currentTimeMillis()`) that this object was created.
    `long` | `getIdleTimeMillis()` Obtain 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).
    `long` | `getLastBorrowTime()` Obtain the time the wrapped object was last borrowed.
    `long` | `getLastReturnTime()` Obtain the time the wrapped object was last returned.
    `long` | `getLastUsedTime()` Return an estimate of the last time this object was used.
    `T` | `getObject()` Obtain the underlying object that is wrapped by this instance of `PooledObject`.
    `PooledObjectState` | `getState()` Returns 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)` 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.
    `boolean` | `startEvictionTest()` Attempt to place the pooled object in the `PooledObjectState.EVICTION` state.
    `String` | `toString()` Provides a String form of the wrapper for debug purposes.
    `void` | `use()` Record the current stack trace as the last time the object was used.

- - ### Method Detail

    - #### getObject

          T getObject()

      Obtain the underlying object that is wrapped by this instance of `PooledObject`.
      Returns:
        The wrapped object

    - #### getCreateTime

          long getCreateTime()

      Obtain the time (using the same basis as `System.currentTimeMillis()`) that this object was created.
      Returns:
        The creation time for the wrapped object

    - #### getActiveTimeMillis

          long getActiveTimeMillis()

      Obtain 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

    - #### getIdleTimeMillis

          long getIdleTimeMillis()

      Obtain 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

    - #### getLastBorrowTime

          long getLastBorrowTime()

      Obtain the time the wrapped object was last borrowed.
      Returns:
        The time the object was last borrowed

    - #### getLastReturnTime

          long getLastReturnTime()

      Obtain the time the wrapped object was last returned.
      Returns:
        The time the object was last returned

    - #### getLastUsedTime

          long getLastUsedTime()

      Return 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.getLastUsed()` and `getLastBorrowTime()`; otherwise this method gives the same value as `getLastBorrowTime()`.
      Returns:
        the last time this object was used

    - #### compareTo

          int 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:
        `compareTo` in interface `Comparable<PooledObject<T>>`

    - #### equals

          boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          String toString()

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

      Overrides:
        `toString` in class `Object`

    - #### startEvictionTest

          boolean startEvictionTest()

      Attempt to place the pooled object in the `PooledObjectState.EVICTION` state.
      Returns:
        `true` if the object was placed in the `PooledObjectState.EVICTION` state otherwise `false`

    - #### endEvictionTest

          boolean endEvictionTest(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

    - #### allocate

          boolean allocate()

      Allocates the object.
      Returns:
        `true` if the original state was `IDLE`

    - #### deallocate

          boolean deallocate()

      Deallocates the object and sets it `IDLE` if it is currently `ALLOCATED`.
      Returns:
        `true` if the state was `ALLOCATED`

    - #### invalidate

          void invalidate()

      Sets the state to `INVALID`

    - #### setLogAbandoned

          void 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

    - #### use

          void use()

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

    - #### printStackTrace

          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` - The destination for the debug output

    - #### getState

          PooledObjectState getState()

      Returns the state of this object.
      Returns:
        state

    - #### markAbandoned

          void markAbandoned()

      Marks the pooled object as abandoned.

    - #### markReturning

          void markReturning()

      Marks the object as returning to the pool.

Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.