void () { try { final String path = (String)myControllerClass.getMethod("capturePerformanceSnapshot").invoke(myController); String message = "CPU Snapshot captured: " + path; LOG.warn(message); System.err.println(message); myControllerClass.getMethod("stopCpuProfiling").invoke(myController); } catch (Throwable e) { e.printStackTrace(); LOG.error(e); } }