Package org.glassfish.common.util
Class InstanceCounter
- java.lang.Object
-
- org.glassfish.common.util.InstanceCounter
-
public class InstanceCounter extends Object
Counts instances of a particular class, helpful in leak detectionExample: Put the following line into the class you want counted:
private final InstanceCounter instanceCounter = new InstanceCounter<>(this);
- Author:
- Cuba Stanley
-
-
Constructor Summary
Constructors Constructor Description InstanceCounter(Object counted)
triggers instance counting of the specified
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getInstanceCount(Class<?> countedType, long timeout)
Returns instance count of a particular class.static Set<WeakReference<?>>
getInstances(Class<?> countedType, long timeout)
gets actual references to counted objects
-
-
-
Constructor Detail
-
InstanceCounter
public InstanceCounter(Object counted)
triggers instance counting of the specified- Parameters:
counted
- object to be counted
-
-
Method Detail
-
getInstanceCount
public static int getInstanceCount(Class<?> countedType, long timeout)
Returns instance count of a particular class.- Parameters:
countedType
-timeout
- in milliseconds to wait to collect removed instances- Returns:
- current instance count
-
getInstances
public static Set<WeakReference<?>> getInstances(Class<?> countedType, long timeout)
gets actual references to counted objects- Parameters:
countedType
-timeout
- in milliseconds- Returns:
- list of counted objects
-
-