@Test public void testSchedulerRunFixedRateSkipIfLong() { Registry r = new DefaultRegistry(); MeasurableScheduler scheduler = new MeasurableScheduler(r, "fixed-rate", 1); AL.set(0); final AtomicLong latecount = new AtomicLong(0); scheduler.scheduleAtFixedRateSkipIfLong(new Runnable() { @Override public void run() { AL.incrementAndGet(); Random r = new Random(); int sleep = r.nextInt(150); if (sleep >= 100) latecount.incrementAndGet(); 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()); }
public ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(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), true)); delayedExecute(t); return t; }
MeasurableScheduler extends ThreadPoolExecutor implements ScheduledExecutorService,
                                                           ScheduledService { public ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(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), true)); delayedExecute(t); return t; } }
MeasurableScheduler extends ThreadPoolExecutor implements ScheduledExecutorService,
                                                           ScheduledService { public ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(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), true)); delayedExecute(t); return t; } MeasurableScheduler(final Registry registry, final String name, int poolSize); }
MeasurableScheduler extends ThreadPoolExecutor implements ScheduledExecutorService,
                                                           ScheduledService { public ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(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), true)); 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); }
MeasurableScheduler extends ThreadPoolExecutor implements ScheduledExecutorService,
                                                           ScheduledService { public ScheduledFuture<?> scheduleAtFixedRateSkipIfLong(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), true)); 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);  }