org.thymeleaf.util
Class ResourcePool<T>

Object
  extended by org.thymeleaf.util.ResourcePool<T>

public final class ResourcePool<T>
extends Object

Represents a limited set or pool of resources, which needs to be used with exclusive ownership.

Should be used in a similar fashion to the following so that resources are always released properly:

   MyResource resource = myLimitedResource.allocate();
   try {
       // actual code using the resource
   } finally {
       myLimitedResource.release(resource);
   }
 

Since:
2.0.0
Author:
Guven Demir

Constructor Summary
ResourcePool(java.util.Collection<T> resources)
           
 
Method Summary
 T allocate()
           Allocates and returns a resource from the pool.
 void release(T resource)
           Releases a previously allocated resource.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcePool

public ResourcePool(java.util.Collection<T> resources)
Method Detail

allocate

public T allocate()

Allocates and returns a resource from the pool.

Blocks until a resource is available when a resource is not available immediately.

Returns:
the allocated resource, heving been removed from the allocation pool.

release

public void release(T resource)

Releases a previously allocated resource.

Might also be used to introduce new resources, e.g. in place of a broken resource.



Copyright © 2012 The THYMELEAF team. All Rights Reserved.