MetricStatisticsProvider implements StatisticsProvider, Closeable { @Override public MeterStats getMeter(String name, StatsOptions options) { return getStats(name, StatsBuilder.METERS, options); } MetricStatisticsProvider(MBeanServer server, ScheduledExecutorService executor); void close(); @Override RepositoryStatistics getStats(); @Override MeterStats getMeter(String name, StatsOptions options); @Override CounterStats getCounterStats(String name, StatsOptions options); @Override TimerStats getTimer(String name, StatsOptions options); @Override HistogramStats getHistogram(String name, StatsOptions options); MetricRegistry getRegistry();  }
@Test public void concurrentAccess() throws Exception{ final Queue<MeterStats> statsQueue = new ConcurrentLinkedDeque<MeterStats>(); List<Thread> threads = Lists.newArrayList(); int numWorker = 5; final CountDownLatch latch = new CountDownLatch(1); for (int i = 0; i < numWorker; i++) { threads.add(new Thread(new Runnable() { @Override public void run() { Uninterruptibles.awaitUninterruptibly(latch); statsQueue.add(statsProvider.getMeter("foo", StatsOptions.DEFAULT)); } })); } for (Thread t : threads){ t.start(); } latch.countDown(); for (Thread t : threads){ t.join(); } Set<MeterStats> statsSet = Sets.newIdentityHashSet(); for (MeterStats m : statsQueue){ statsSet.add(m); } assertEquals(1, statsSet.size()); }