PerformanceMonitor { public static <T> T callAndMonitor( final long warnMillis, final long errorMillis, final Callable<T> callable) throws Exception { return performanceMonitoredCallable(warnMillis, errorMillis, callable).call(); } private  PerformanceMonitor(); static T callAndMonitor(
          final long warnMillis, final long errorMillis, final Callable<T> callable); static T callAndMonitor(final MeasurementRecorderSource mrs,
          final long warnMillis, final long errorMillis, final Callable<T> callable); static T callAndMonitor(final MeasurementRecorderSource mrs,
          final long warnMillis, final long errorMillis, final Callable<T> callable,
          final boolean isLogInfo, final Object... detail); static Callable<T> performanceMonitoredCallable(final MeasurementRecorderSource mrs,
          final long warnMillis, final long errorMillis, final Callable<T> callable); static Callable<T> performanceMonitoredCallable(final MeasurementRecorderSource mrs,
          final long warnMillis, final long errorMillis, final Callable<T> callable,
          final boolean isLogInfo, final Object... detail); static Callable<T> performanceMonitoredCallable(
          final long warnMillis, final long errorMillis, final Callable<T> callable); static Callable<T> performanceMonitoredCallable(
          final long warnMillis, final long errorMillis, final Callable<T> callable,
          final boolean isLogInfo, final Object... detail); static Callable<T> performanceMonitoredCallable(final MeasurementRecorder mr,
          final long warnMillis, final long errorMillis, final Callable<T> callable,
          final boolean isLogInfo, final Object... detail);  }
@Test public void testSomeMethod() throws Exception { LogAssert expect = TestLoggers.sys().expect("org.spf4j.perf.PerformanceMonitor", Level.ERROR, LogMatchers.hasFormat("Execution time {} ms for {} exceeds error threshold of {} ms, detail: {}")); String result = PerformanceMonitor.callAndMonitor( 1, 2, new Callable<String>() { @Override @SuppressFBWarnings("MDM_THREAD_YIELD") public String call() throws Exception { LOG.debug("testing"); Thread.sleep(3); return "test"; } @Override public String toString() { return "test"; } }); Assert.assertEquals("test", result); expect.assertObservation(); }