AbandonedTrace (Apache Tomcat 11.0.23 API Documentation)
Description: declaration: package: org.apache.tomcat.dbcp.dbcp2, class: AbandonedTrace

# Class AbandonedTrace

java.lang.Object
org.apache.tomcat.dbcp.dbcp2.AbandonedTrace

All Implemented Interfaces:
  `AutoCloseable, TrackedUse`

Direct Known Subclasses:
  `DelegatingConnection, DelegatingResultSet, DelegatingStatement`

public class AbandonedTrace extends Object implements TrackedUse, AutoCloseable
Tracks connection usage for recovering and reporting abandoned connections.

The JDBC Connection, Statement, and ResultSet classes extend this class.

Since:
  2.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbandonedTrace()`
  Creates a new AbandonedTrace without config and without doing abandoned tracing.
  `AbandonedTrace(AbandonedTrace parent)`
  Constructs a new AbandonedTrace with a parent object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addTrace(AbandonedTrace trace)`
  Adds an object to the list of objects being traced.
  `protected void`
  `clearTrace()`
  Clears the list of objects being traced by this object.
  `void`
  `close()`
  Subclasses can implement this nop.
  `protected void`
  `close(Consumer<Exception> exceptionHandler)`
  Closes this resource and if an exception is caught, then calls `exceptionHandler`.
  `long`
  `getLastUsed()`
  Deprecated.
  `Instant`
  `getLastUsedInstant()`
  Gets the last Instant this object was used.
  `protected List<AbandonedTrace>`
  `getTrace()`
  Gets a list of objects being traced by this object.
  `protected void`
  `removeThisTrace(Object source)`
  Removes this object the source object is tracing.
  `protected void`
  `removeTrace(AbandonedTrace trace)`
  Removes a child object this object is tracing.
  `protected void`
  `setLastUsed()`
  Sets the time this object was last used to the current time in milliseconds.
  `protected void`
  `setLastUsed(long lastUsedMillis)`
  Deprecated.
  Use `setLastUsed(Instant)`
  `protected void`
  `setLastUsed(Instant lastUsedInstant)`
  Sets the instant this object was last used.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AbandonedTrace

    public AbandonedTrace()
    Creates a new AbandonedTrace without config and without doing abandoned tracing.

  - ### AbandonedTrace

    public AbandonedTrace(AbandonedTrace parent)
    Constructs a new AbandonedTrace with a parent object.
    Parameters:
      `parent` - AbandonedTrace parent object.

- ## Method Details

  - ### addTrace

    protected void addTrace(AbandonedTrace trace)
    Adds an object to the list of objects being traced.
    Parameters:
      `trace` - AbandonedTrace object to add.

  - ### clearTrace

    protected void clearTrace()
    Clears the list of objects being traced by this object.

  - ### close

    public void close() throws SQLException
    Subclasses can implement this nop.
    Specified by:
      `close` in interface `AutoCloseable`
    Throws:
      `SQLException` - Ignored here, for subclasses.
    Since:
      2.10.0

  - ### close

    protected void close(Consumer<Exception> exceptionHandler)
    Closes this resource and if an exception is caught, then calls `exceptionHandler`.
    Parameters:
      `exceptionHandler` - Consumes exception thrown closing this resource.
    Since:
      2.10.0

  - ### getLastUsed

    @Deprecated public long getLastUsed()
    Deprecated.
    Gets the last time this object was used in milliseconds.
    Specified by:
      `getLastUsed` in interface `TrackedUse`
    Returns:
      long time in milliseconds.

  - ### getLastUsedInstant

    public Instant getLastUsedInstant()
    Description copied from interface: `TrackedUse`
    Gets the last Instant this object was used.

    Starting with Java 9, the JRE `SystemClock` precision is increased usually down to microseconds, or tenth of microseconds, depending on the OS, Hardware, and JVM implementation.

    Specified by:
      `getLastUsedInstant` in interface `TrackedUse`
    Returns:
      the last Instant this object was used.

  - ### getTrace

    protected List<AbandonedTrace> getTrace()
    Gets a list of objects being traced by this object.
    Returns:
      List of objects.

  - ### removeThisTrace

    protected void removeThisTrace(Object source)
    Removes this object the source object is tracing.
    Parameters:
      `source` - The object tracing
    Since:
      2.7.0

  - ### removeTrace

    protected void removeTrace(AbandonedTrace trace)
    Removes a child object this object is tracing.
    Parameters:
      `trace` - AbandonedTrace object to remove.

  - ### setLastUsed

    protected void setLastUsed()
    Sets the time this object was last used to the current time in milliseconds.

  - ### setLastUsed

    protected void setLastUsed(Instant lastUsedInstant)
    Sets the instant this object was last used.
    Parameters:
      `lastUsedInstant` - instant.
    Since:
      2.10.0

  - ### setLastUsed

    @Deprecated protected void setLastUsed(long lastUsedMillis)
    Deprecated.
    Use `setLastUsed(Instant)`
    Sets the time in milliseconds this object was last used.
    Parameters:
      `lastUsedMillis` - time in milliseconds.