MeasurableScheduler extends ThreadPoolExecutor implements ScheduledExecutorService,
                                                           ScheduledService { @Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { if (command == null || unit == null) throw new NullPointerException(); if (period <= 0) throw new IllegalArgumentException(); RunnableScheduledFuture<?> t = decorateTask( command, new MeasurableScheduler.ScheduledFutureTask<Object>(command, null, triggerTime( initialDelay, unit), unit.toNanos(period))); delayedExecute(t); return t; } MeasurableScheduler(final Registry registry, final String name, int poolSize); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(Runnable command, long initialDelay,
                                                            long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period,
                                                  TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
                                                     long delay, TimeUnit unit);  }
@Test public void testSchedulerRunFixedRate() { Registry r = new DefaultRegistry(); MeasurableScheduler scheduler = new MeasurableScheduler(r, "fixed-rate", 1); AL.set(0); scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { AL.incrementAndGet(); Random r = new Random(); int sleep = r.nextInt(150); try { Thread.sleep(sleep); } catch (InterruptedException e) { System.err.println("eeee"); } System.out.println("--sleep:" + sleep + "--now:" + System.currentTimeMillis()); } }, 0, 100, TimeUnit.MILLISECONDS); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } scheduler.shutdown(); String str = printMetrics(r); System.out.println("_____________" + AL.get()); }