Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cern::util::testhelpers::GarbageCollectionTestHelper Class Reference

List of all members.

Public Member Functions

 GarbageCollectionTestHelper (Object refToSurveil)
boolean waitForGC ()
boolean waitForGC (long maxTimeout)
boolean complexWaitForGC (long maxTimeout)
void cancel ()

Private Attributes

Reference ref
ReferenceQueue refQ
volatile boolean cancelFlag = false
volatile Thread waitingThread

Static Private Attributes

final long GC_SLICE_MILLIS = 200

Detailed Description

A helper class to check if Garbage Collection works properly. It allows you to check whether an object is freed by the Garbage Collector.

To check whether an object is garbage collected, create an instance of this class and pass it the reference the object in to be surveilled for GC. Then, call the method waitForGC() to wait until the object is garbage collected. Here is sample code:


      Object obj = new Object();
      GarbageCollectionTestHelper gch = new GarbageCollectionTestHelper(obj);

          obj = null; // enable garbage collection

          if (gch.waitForGC(maxTimeoutMillis)) {
              System.out.println("garbage collection ok");
          } else {
              System.err.println("garbage collection problem");
          }
 
You have to use one instance of this class per reference you want to surveil.

This implementation isbased on the java.lang.ref.* classes. It keeps a PhantomReference to the reference and waits until the instance has been garbage collected.

Version:
0.9.1
Author:
Vito Baggiolini


Constructor & Destructor Documentation

cern::util::testhelpers::GarbageCollectionTestHelper::GarbageCollectionTestHelper Object  refToSurveil  )  [inline]
 


Member Function Documentation

void cern::util::testhelpers::GarbageCollectionTestHelper::cancel  )  [inline]
 

boolean cern::util::testhelpers::GarbageCollectionTestHelper::complexWaitForGC long  maxTimeout  )  [inline]
 

a more sophisticated algorithm to wait for Property Change Events

boolean cern::util::testhelpers::GarbageCollectionTestHelper::waitForGC long  maxTimeout  )  [inline]
 

a simple algorithm to wait for GC

boolean cern::util::testhelpers::GarbageCollectionTestHelper::waitForGC  )  [inline]
 


Member Data Documentation

volatile boolean cern::util::testhelpers::GarbageCollectionTestHelper::cancelFlag = false [private]
 

final long cern::util::testhelpers::GarbageCollectionTestHelper::GC_SLICE_MILLIS = 200 [static, private]
 

Reference cern::util::testhelpers::GarbageCollectionTestHelper::ref [private]
 

ReferenceQueue cern::util::testhelpers::GarbageCollectionTestHelper::refQ [private]
 

volatile Thread cern::util::testhelpers::GarbageCollectionTestHelper::waitingThread [private]
 


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 03:09:49 2009 for ACS Java API by doxygen 1.3.8