gcRadar SimpleObjectSingleThreadedMonitor Example
/*This file is part of gcRadar.
gcRadar is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation version 3 of the License.
gcRadar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with gcRadar. If not, see <http://www.gnu.org/licenses/>.
*/
package test;
import com.gcr.callbacks.GcRadarCallback;
import com.gcr.monitors.SimpleObjectSingleThreadedMonitor;
import com.gcr.structs.AbstractObjectRefrenceKey;
public class SimpleObjectSingleThreadedMonitor_Test implements GcRadarCallback
{
Integer ro = new Integer(678);
public static void main(String[] args)
{
SimpleObjectSingleThreadedMonitor_Test gcMoniterTest = new SimpleObjectSingleThreadedMonitor_Test();
gcMoniterTest.doTest();
}
private void doTest()
{
System.out.println("GCMoniterTest.doTest()");
SimpleObjectSingleThreadedMonitor sequentialObjectMonitor = new SimpleObjectSingleThreadedMonitor();
for (int i = 0; i < 100; i++)
{
Integer o = new Integer(5);
sequentialObjectMonitor.addObject(o, "MyObject - " + i, this);
}
sequentialObjectMonitor.startMonitoring();
sequentialObjectMonitor.addObject(ro, this);
try
{
Thread.sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(sequentialObjectMonitor.getPendingObjectsCount());
System.out.println(sequentialObjectMonitor.getPendingObjects());
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
ro = null;
try
{
Thread.sleep(2000);
System.gc();
System.out.println(sequentialObjectMonitor.getPendingObjectsCount());
System.out.println(sequentialObjectMonitor.getPendingObjects());
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
@Override
public <T> void objectReclaimedByGC(AbstractObjectRefrenceKey<T> refrenceKey)
{
System.out.println(" - GCed - " + refrenceKey.getObjRefrenceKey() + " at " + refrenceKey.getPhantomCallbackTime());
}
@Override
public <T> void noSurvivingRefrence(AbstractObjectRefrenceKey<T> objWrapper)
{
System.out.println(" - About to GC - " + objWrapper.getObjRefrenceKey() + " at " + objWrapper.getWeakCallbackTime());
}
}