Class AbandonedConfig
- java.lang.Object
-
- org.apache.commons.pool2.impl.AbandonedConfig
-
public class AbandonedConfig extends java.lang.ObjectConfiguration settings for abandoned object removal.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private static java.time.DurationDEFAULT_REMOVE_ABANDONED_TIMEOUT_DURATIONThe 5 minutes Duration.private booleanlogAbandonedDetermines whether or not to log stack traces for application code which abandoned an object.private java.io.PrintWriterlogWriterPrintWriter to use to log information on abandoned objects.private booleanremoveAbandonedOnBorrowWhether or not borrowObject performs abandoned object removal.private booleanremoveAbandonedOnMaintenanceWhether or not pool maintenance (evictor) performs abandoned object removal.private java.time.DurationremoveAbandonedTimeoutDurationTimeout before an abandoned object can be removed.private booleanrequireFullStackTraceDetermines whether or not to log full stack traces when logAbandoned is true.private booleanuseUsageTrackingIf the pool implementsUsageTracking, should the pool record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects?
-
Constructor Summary
Constructors Modifier Constructor Description AbandonedConfig()Creates a new instance.privateAbandonedConfig(AbandonedConfig abandonedConfig)Creates a new instance with values from the given instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AbandonedConfigcopy(AbandonedConfig abandonedConfig)Creates a new instance with values from the given instance.booleangetLogAbandoned()Flag to log stack traces for application code which abandoned an object.java.io.PrintWritergetLogWriter()Gets the log writer being used by this configuration to log information on abandoned objects.booleangetRemoveAbandonedOnBorrow()Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when borrowObject is invoked.booleangetRemoveAbandonedOnMaintenance()Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when pool maintenance (the "evictor") runs.intgetRemoveAbandonedTimeout()Deprecated.java.time.DurationgetRemoveAbandonedTimeoutDuration()Timeout before an abandoned object can be removed.booleangetRequireFullStackTrace()Indicates if full stack traces are required whenlogAbandonedis true.booleangetUseUsageTracking()If the pool implementsUsageTracking, should the pool record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects?voidsetLogAbandoned(boolean logAbandoned)Sets the flag to log stack traces for application code which abandoned an object.voidsetLogWriter(java.io.PrintWriter logWriter)Sets the log writer to be used by this configuration to log information on abandoned objects.voidsetRemoveAbandonedOnBorrow(boolean removeAbandonedOnBorrow)Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when borrowObject is invoked.voidsetRemoveAbandonedOnMaintenance(boolean removeAbandonedOnMaintenance)Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when pool maintenance runs.voidsetRemoveAbandonedTimeout(int removeAbandonedTimeoutSeconds)Deprecated.voidsetRemoveAbandonedTimeout(java.time.Duration removeAbandonedTimeout)Sets the timeout before an abandoned object can be removed.voidsetRequireFullStackTrace(boolean requireFullStackTrace)Sets the flag to require full stack traces for logging abandoned connections when enabled.voidsetUseUsageTracking(boolean useUsageTracking)If the pool implementsUsageTracking, configure whether the pool should record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects.java.lang.StringtoString()
-
-
-
Field Detail
-
DEFAULT_REMOVE_ABANDONED_TIMEOUT_DURATION
private static final java.time.Duration DEFAULT_REMOVE_ABANDONED_TIMEOUT_DURATION
The 5 minutes Duration.
-
removeAbandonedOnBorrow
private boolean removeAbandonedOnBorrow
Whether or not borrowObject performs abandoned object removal.
-
removeAbandonedOnMaintenance
private boolean removeAbandonedOnMaintenance
Whether or not pool maintenance (evictor) performs abandoned object removal.
-
removeAbandonedTimeoutDuration
private java.time.Duration removeAbandonedTimeoutDuration
Timeout before an abandoned object can be removed.
-
logAbandoned
private boolean logAbandoned
Determines whether or not to log stack traces for application code which abandoned an object.
-
requireFullStackTrace
private boolean requireFullStackTrace
Determines whether or not to log full stack traces when logAbandoned is true. If disabled, then a faster method for logging stack traces with only class data may be used if possible.- Since:
- 2.5
-
logWriter
private java.io.PrintWriter logWriter
PrintWriter to use to log information on abandoned objects. Use of default system encoding is deliberate.
-
useUsageTracking
private boolean useUsageTracking
If the pool implementsUsageTracking, should the pool record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects?
-
-
Constructor Detail
-
AbandonedConfig
public AbandonedConfig()
Creates a new instance.
-
AbandonedConfig
private AbandonedConfig(AbandonedConfig abandonedConfig)
Creates a new instance with values from the given instance.- Parameters:
abandonedConfig- the source.
-
-
Method Detail
-
copy
public static AbandonedConfig copy(AbandonedConfig abandonedConfig)
Creates a new instance with values from the given instance.- Parameters:
abandonedConfig- the source, may be null.- Returns:
- A new instance or null if the input is null.
- Since:
- 2.11.0
-
getLogAbandoned
public boolean getLogAbandoned()
Flag to log stack traces for application code which abandoned an object. Defaults to false. Logging of abandoned objects adds overhead for every object created because a stack trace has to be generated.- Returns:
- boolean true if stack trace logging is turned on for abandoned objects
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Gets the log writer being used by this configuration to log information on abandoned objects. If not set, a PrintWriter based on System.out with the system default encoding is used.- Returns:
- log writer in use
-
getRemoveAbandonedOnBorrow
public boolean getRemoveAbandonedOnBorrow()
Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when borrowObject is invoked.
The default value is false.
If set to true, abandoned objects are removed by borrowObject if there are fewer than 2 idle objects available in the pool and
getNumActive() > getMaxTotal() - 3- Returns:
- true if abandoned objects are to be removed by borrowObject
-
getRemoveAbandonedOnMaintenance
public boolean getRemoveAbandonedOnMaintenance()
Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when pool maintenance (the "evictor") runs.
The default value is false.
If set to true, abandoned objects are removed by the pool maintenance thread when it runs. This setting has no effect unless maintenance is enabled by setting
BaseGenericObjectPool.getDurationBetweenEvictionRuns()to a positive number.- Returns:
- true if abandoned objects are to be removed by the evictor
-
getRemoveAbandonedTimeout
@Deprecated public int getRemoveAbandonedTimeout()
Deprecated.Timeout in seconds before an abandoned object can be removed.
The time of most recent use of an object is the maximum (latest) of
TrackedUse.getLastUsedInstant()(if this class of the object implements TrackedUse) and the time when the object was borrowed from the pool.The default value is 300 seconds.
- Returns:
- the abandoned object timeout in seconds.
-
getRemoveAbandonedTimeoutDuration
public java.time.Duration getRemoveAbandonedTimeoutDuration()
Timeout before an abandoned object can be removed.
The time of most recent use of an object is the maximum (latest) of
TrackedUse.getLastUsedInstant()(if this class of the object implements TrackedUse) and the time when the object was borrowed from the pool.The default value is 300 seconds.
- Returns:
- the abandoned object timeout.
- Since:
- 2.10.0
-
getRequireFullStackTrace
public boolean getRequireFullStackTrace()
Indicates if full stack traces are required whenlogAbandonedis true. Defaults to true. Logging of abandoned objects requiring a full stack trace will generate an entire stack trace to generate for every object created. If this is disabled, a faster but less informative stack walking mechanism may be used if available.- Returns:
- true if full stack traces are required for logging abandoned connections, or false if abbreviated stack traces are acceptable
- Since:
- 2.5
- See Also:
CallStack
-
getUseUsageTracking
public boolean getUseUsageTracking()
If the pool implementsUsageTracking, should the pool record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects?- Returns:
trueif usage tracking is enabled
-
setLogAbandoned
public void setLogAbandoned(boolean logAbandoned)
Sets the flag to log stack traces for application code which abandoned an object.- Parameters:
logAbandoned- true turns on abandoned stack trace logging- See Also:
getLogAbandoned()
-
setLogWriter
public void setLogWriter(java.io.PrintWriter logWriter)
Sets the log writer to be used by this configuration to log information on abandoned objects.- Parameters:
logWriter- The new log writer
-
setRemoveAbandonedOnBorrow
public void setRemoveAbandonedOnBorrow(boolean removeAbandonedOnBorrow)
Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when borrowObject is invoked.- Parameters:
removeAbandonedOnBorrow- true means abandoned objects will be removed by borrowObject- See Also:
getRemoveAbandonedOnBorrow()
-
setRemoveAbandonedOnMaintenance
public void setRemoveAbandonedOnMaintenance(boolean removeAbandonedOnMaintenance)
Flag to remove abandoned objects if they exceed the removeAbandonedTimeout when pool maintenance runs.- Parameters:
removeAbandonedOnMaintenance- true means abandoned objects will be removed by pool maintenance- See Also:
getRemoveAbandonedOnMaintenance()
-
setRemoveAbandonedTimeout
public void setRemoveAbandonedTimeout(java.time.Duration removeAbandonedTimeout)
Sets the timeout before an abandoned object can be removed.Setting this property has no effect if
removeAbandonedOnBorrowandremoveAbandonedOnMaintenanceare both false.- Parameters:
removeAbandonedTimeout- new abandoned timeout- Since:
- 2.10.0
- See Also:
getRemoveAbandonedTimeoutDuration()
-
setRemoveAbandonedTimeout
@Deprecated public void setRemoveAbandonedTimeout(int removeAbandonedTimeoutSeconds)
Deprecated.Sets the timeout in seconds before an abandoned object can be removed.Setting this property has no effect if
removeAbandonedOnBorrowandremoveAbandonedOnMaintenanceare both false.- Parameters:
removeAbandonedTimeoutSeconds- new abandoned timeout in seconds- See Also:
getRemoveAbandonedTimeoutDuration()
-
setRequireFullStackTrace
public void setRequireFullStackTrace(boolean requireFullStackTrace)
Sets the flag to require full stack traces for logging abandoned connections when enabled.- Parameters:
requireFullStackTrace- indicates whether or not full stack traces are required in abandoned connection logs- Since:
- 2.5
- See Also:
CallStack,getRequireFullStackTrace()
-
setUseUsageTracking
public void setUseUsageTracking(boolean useUsageTracking)
If the pool implementsUsageTracking, configure whether the pool should record a stack trace every time a method is called on a pooled object and retain the most recent stack trace to aid debugging of abandoned objects.- Parameters:
useUsageTracking- A value oftruewill enable the recording of a stack trace on every use of a pooled object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Since:
- 2.4.3
-
-