used() and max()
methods will return absolute values indicating the amounts used or
available for all resources that come from the shared pool, but the
managed() method will only indicate the amount of the resource
used for managed resources and the target() method will return
the amount of the total shared resource that the allocation methods
should attempt to stay under.
long newsize = ...; // size of new resource allocation
if (pool.used() + newsize >= pool.target()) {
cleanup(pool);
// possibly multiple passes of increasing aggressiveness
}
if (pool.used() + newsize >= pool.max()) {
throw OOM();
}
allocate(newsize);
The amounts and sizes returned from the methods should all be in the
same units, usually bytes.
ManagedResource
| Modifier and Type | Method and Description |
|---|---|
| public void | freeDisposalRequestedAndCheckResources(boolean
true if the caller wishes to forgive
and unlock all outstanding locks on non-permanent resourcesCheck that all resources are in the correct state for an idle condition and free any resources which were disposed from a non-resource thread. |
| public boolean | Returns: true if Thread.currentThread() is a thread that created this ResourcePoolTrue if Thread.currentThread() is a thread that created this ResourcePool |
| public long | Returns: the amount being used to hold managed resourcesThe amount of this resource currently being used to hold managed resources. |
| public long | Returns: the maximum amount of the resourceThe total space available in this pool for allocating any kind of resource, even unmanaged resources, and including those resources already allocated. |
| public long | Returns: the initial target amount of the resource to be usedThe initial target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. |
| public boolean | Returns: true if there is room for the indicated resourcethe size of the resource that is about to be allocated size)Prepare for an allocation of a resource from this pool of the indicated size by freeing up uninteresting resources until the allocation fits within the target() or max() sizes. |
| public void | recordAllocated(long
the amount of the resource to be indicated as managed. size)Record the indicated amount of the resource as being allocated for
a |
| public void | recordFree(long
the amount of the resource to remove from the managed amount. size)Record the indicated amount of the resource as no longer being
held in a |
| public void | resourceFreed(ManagedResource<T>
the resource that is freed, no longer being managed resource)Record the |
| public void | resourceManaged(ManagedResource<T>
the resource that is now being managed resource)Record the |
| public void | setTarget(long
the new current target to be set newTarget)Sets a new current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. |
| public long | Returns: the space within this resource pool that the object occupies.the resource to be measured resource)The estimated size of the indicated resource. |
| public long | Returns: the current target amount of the resource to be usedThe current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. |
| public long | Returns: the amount being usedThe amount of a resource currently being used to hold any kind of resource, whether managed or not. |
| freeDisposalRequestedAndCheckResources | back to summary |
|---|---|
| public void freeDisposalRequestedAndCheckResources(boolean forgiveStaleLocks) Check that all resources are in the correct state for an idle condition
and free any resources which were disposed from a non-resource thread.
This method must be called on a thread that is appropriate for disposing
and managing resources for this resource pool.
The boolean
| |
| isManagerThread | back to summary |
|---|---|
| public boolean isManagerThread() True if Thread.currentThread() is a thread that created this ResourcePool
| |
| managed | back to summary |
|---|---|
| public long managed() The amount of this resource currently being used to hold managed
resources.
This amount may be less than the amount returned by the
| |
| max | back to summary |
|---|---|
| public long max() The total space available in this pool for allocating any kind of resource, even unmanaged resources, and including those resources already allocated.
| |
| origTarget | back to summary |
|---|---|
| public long origTarget() The initial target of the maximum amount of space in this resource pool
that should be used so as to be friendly to other parts of the system.
This number must be less than or equal to the amount returned by the
| |
| prepareForAllocation | back to summary |
|---|---|
| public boolean prepareForAllocation(long size) Prepare for an allocation of a resource from this pool of the indicated size by freeing up uninteresting resources until the allocation fits within the target() or max() sizes.
| |
| recordAllocated | back to summary |
|---|---|
| public void recordAllocated(long size) Record the indicated amount of the resource as being allocated for
a
| |
| recordFree | back to summary |
|---|---|
| public void recordFree(long size) Record the indicated amount of the resource as no longer being
held in a
| |
| resourceFreed | back to summary |
|---|---|
| public void resourceFreed(ManagedResource<T> resource) Record the
| |
| resourceManaged | back to summary |
|---|---|
| public void resourceManaged(ManagedResource<T> resource) Record the
| |
| setTarget | back to summary |
|---|---|
| public void setTarget(long newTarget) Sets a new current target of the maximum amount of space in this
resource pool that should be used so as to be friendly to other parts
of the system.
The specified
| |
| size | back to summary |
|---|---|
| public long size(T resource) The estimated size of the indicated resource.
| |
| target | back to summary |
|---|---|
| public long target() The current target of the maximum amount of space in this resource pool
that should be used so as to be friendly to other parts of the system.
This number must be less than or equal to the amount returned by the
| |
| used | back to summary |
|---|---|
| public long used() The amount of a resource currently being used to hold any kind of resource, whether managed or not.
| |