T
- the type of object in the poolpublic class DefaultPooledObject<T> extends java.lang.Object implements PooledObject<T>
This class is intended to be thread-safe.
构造器和说明 |
---|
DefaultPooledObject(T object)
Creates a new instance that wraps the provided object so that the pool can
track the state of the pooled object.
|
限定符和类型 | 方法和说明 |
---|---|
boolean |
allocate()
Allocates the object.
|
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.
|
boolean |
deallocate()
|
boolean |
endEvictionTest(java.util.Deque<PooledObject<T>> idleQueue)
Called to inform the object that the eviction test has ended.
|
long |
getActiveTimeMillis()
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).
|
long |
getBorrowedCount()
Gets the number of times this object has been borrowed.
|
long |
getCreateTime()
Gets the time (using the same basis as
System.currentTimeMillis() ) that this object was created. |
long |
getIdleTimeMillis()
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).
|
long |
getLastBorrowTime()
Gets the time the wrapped object was last borrowed.
|
long |
getLastReturnTime()
Gets the time the wrapped object was last returned.
|
long |
getLastUsedTime()
Gets an estimate of the last time this object was used.
|
T |
getObject()
Gets the underlying object that is wrapped by this instance of
PooledObject . |
PooledObjectState |
getState()
Gets the state of this object.
|
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(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.
|
void |
setLogAbandoned(boolean logAbandoned)
Is abandoned object tracking being used?
|
void |
setRequireFullStackTrace(boolean requireFullStackTrace)
Configures the stack trace generation strategy based on whether or not fully
detailed stack traces are required.
|
boolean |
startEvictionTest()
Attempts to place the pooled object in the
PooledObjectState.EVICTION state. |
java.lang.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.
|
equals, getActiveTime, getIdleTime, hashCode
public DefaultPooledObject(T object)
object
- The object to wrappublic boolean allocate()
allocate
在接口中 PooledObject<T>
true
if the original state was IDLE
public int compareTo(PooledObject<T> other)
PooledObject
Note: This class has a natural ordering that is inconsistent with equals if distinct objects have the same identity hash code.
compareTo
在接口中 java.lang.Comparable<PooledObject<T>>
compareTo
在接口中 PooledObject<T>
public boolean deallocate()
deallocate
在接口中 PooledObject<T>
true
if the state was ALLOCATED
or RETURNING
.public boolean endEvictionTest(java.util.Deque<PooledObject<T>> idleQueue)
PooledObject
endEvictionTest
在接口中 PooledObject<T>
idleQueue
- The queue of idle objects to which the object should be
returnedpublic long getActiveTimeMillis()
PooledObject
getActiveTimeMillis
在接口中 PooledObject<T>
public long getBorrowedCount()
getBorrowedCount
在接口中 PooledObject<T>
public long getCreateTime()
PooledObject
System.currentTimeMillis()
) that this object was created.getCreateTime
在接口中 PooledObject<T>
public long getIdleTimeMillis()
PooledObject
getIdleTimeMillis
在接口中 PooledObject<T>
public long getLastBorrowTime()
PooledObject
getLastBorrowTime
在接口中 PooledObject<T>
public long getLastReturnTime()
PooledObject
getLastReturnTime
在接口中 PooledObject<T>
public long getLastUsedTime()
TrackedUse
, what is returned is
the maximum of TrackedUse.getLastUsed()
and
getLastBorrowTime()
; otherwise this method gives the same
value as getLastBorrowTime()
.getLastUsedTime
在接口中 PooledObject<T>
public T getObject()
PooledObject
PooledObject
.getObject
在接口中 PooledObject<T>
public PooledObjectState getState()
getState
在接口中 PooledObject<T>
public void invalidate()
INVALID
invalidate
在接口中 PooledObject<T>
public void markAbandoned()
markAbandoned
在接口中 PooledObject<T>
public void markReturning()
markReturning
在接口中 PooledObject<T>
public void printStackTrace(java.io.PrintWriter writer)
PooledObject
printStackTrace
在接口中 PooledObject<T>
writer
- The destination for the debug outputpublic void setLogAbandoned(boolean logAbandoned)
PooledObject
setLogAbandoned
在接口中 PooledObject<T>
logAbandoned
- The new configuration setting for abandoned
object trackingpublic void setRequireFullStackTrace(boolean requireFullStackTrace)
setRequireFullStackTrace
在接口中 PooledObject<T>
requireFullStackTrace
- the new configuration setting for abandoned object
loggingpublic boolean startEvictionTest()
PooledObject
PooledObjectState.EVICTION
state.startEvictionTest
在接口中 PooledObject<T>
true
if the object was placed in the
PooledObjectState.EVICTION
state otherwise
false
public java.lang.String toString()
PooledObject
toString
在接口中 PooledObject<T>
toString
在类中 java.lang.Object
public void use()
PooledObject
use
在接口中 PooledObject<T>