import java.util.*; public class TestThreadRunner extends Thread { public TestThreadRunner() { super(); Count++; } private List locall; private static List l; public static void main(String[] args) { long maxMem = 0; long max = 0; long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { new TestThreadRunner().start(); System.gc(); // Keep track of max number of threads that are executing simultaneously (as long as finalize is // being driven appropriately) if (Count > max) max = Count; // Keep track of maximum memory we use long mem = Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory(); if (mem>maxMem) maxMem = mem; } System.err.println("Using ThreadLocal mgmt = "+!org.aspectj.runtime.internal.CFlowStack.getThreadStackFactoryClassName().endsWith("11")); System.err.println("Max memory used through the run = " + maxMem); System.err.println("Time to execute the program = " + (System.currentTimeMillis() - start)); } static { l = new ArrayList(); for (int i = 0; i < 20000; i++) l.add("thisisalongstringithinkaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } public void foo() { locall = new ArrayList(); locall.addAll(l); } public void run() { foo(); } public static long Count = 0; protected void finalize() throws java.lang.Throwable { Count--; //System.out.println("I have now threads "+Count+" Consumed Time "+all); super.finalize(); } } aspect RunCflow percflow(runexec()) { public pointcut runexec() : execution(public void TestThreadRunner.run()); long start, stop; public static long longest = 0; public static long all = 0; Object around() : runexec() { start = System.currentTimeMillis(); Object obj = proceed(); stop = System.currentTimeMillis(); all = all + stop - start; if ((stop-start)>longest) longest=(stop -start); return obj; } }