Package org.kuali.rice.krad.uif.util
Class RecycleUtils
java.lang.Object
org.kuali.rice.krad.uif.util.RecycleUtils
Simple utility class for implementing an object recycling factory pattern.
Weak references to objects are held by a thread-local queue. When a process has finished working
with an object, the recycle(java.lang.Object) method may be offer the recycled object to the queue for
consideration as reusable on the same thread.
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidclean(T instance) Clean all instance fields.static <T> voidClean all instance fields, walking up the class hierarchy to the indicated super class.static <T> TgetInstance(Class<T> c) Get an instance of the given class that has previously been recycled on the same thread, or a new instance using a default constructor if a recycled instance is not available.static <T> TgetRecycledInstance(Class<T> c) Get an instance of the given class that has previously been recycled on the same thread, if an instance of available.static <T> TgetRecycledInstance(String name, Class<T> c) Get an instance of the given class that has previously been recycled on the same thread, if an instance of available.static voidRecycle a instance by its class, for later retrieval in the same thread.static voidRecycle a instance by its class and given name, for later retrieval in the same thread.static voidRecycle a instance by the given class and given name, for later retrieval in the same thread.
-
Method Details
-
getRecycledInstance
Get an instance of the given class that has previously been recycled on the same thread, if an instance of available.- Type Parameters:
T- recycled instance type- Parameters:
c- class to get instance of- Returns:
- instance of the given class previously recycled on the same thread, if one is available. If no instance is available, then null is returned.
-
getRecycledInstance
Get an instance of the given class that has previously been recycled on the same thread, if an instance of available.- Type Parameters:
T- recycled instance type- Parameters:
name- bean namec- class to get instance of- Returns:
- instance of the given class previously recycled on the same thread, if one is available. If no instance is available, then null is returned.
-
getInstance
Get an instance of the given class that has previously been recycled on the same thread, or a new instance using a default constructor if a recycled instance is not available.- Type Parameters:
T- recycled instance type- Parameters:
c- class to get instance of- Returns:
- An instance of the given class previously recycled on the same thread, if one is available. If no instance is available, then null is returned
-
recycle
Recycle a instance by its class, for later retrieval in the same thread.Note that this method does not clean the instance, it only queues it for later retrieval by
getRecycledInstance(Class). The state of the instance should be cleared before passing to this method. For a flexible means to clean instances using reflectionclean(Object, Class)may be considered, however note that a manually implemented clean operation will generally perform faster.- Parameters:
instance- instance to recycle
-
recycle
Recycle a instance by its class and given name, for later retrieval in the same thread.- Parameters:
name- bean nameinstance- instance to recycle- See Also:
-
recycle
Recycle a instance by the given class and given name, for later retrieval in the same thread.- Parameters:
name- bean nameinstance- instance to recyclerecycleClass- class to register the instance under- See Also:
-
clean
public static <T> void clean(T instance) Clean all instance fields.- Type Parameters:
T- recycled instance type- Parameters:
instance- instance to clean
-
clean
Clean all instance fields, walking up the class hierarchy to the indicated super class.- Type Parameters:
T- recycled instance type- Parameters:
instance- instance to cleantop- point in the class hierarchy at which to stop cleaning fields
-