final private void trace(final String action, final int counter) { if( traces.size() < MAX_TRACES) { Exception ex = new Exception() { public String toString() { return "Trace "+(traces.size()+1)+": "+action+", counter: "+counter+", thread: "+Thread.currentThread().getName(); } }; String squashed = squash(ex.getStackTrace()); if( squashed == null ) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); traces.add("\n"+sw); } // else { // traces.add("\n"+ex.toString()+"\n at "+squashed+"\n"); // } } else if (traces.size() == MAX_TRACES) { traces.add("MAX_TRACES reached... no more traces will be recorded."); } }