@Override public void run() { while (true) { try { Thread.sleep(exportInterval); } catch (InterruptedException ie) { // Preserve the interruption status as per guidance and stop doing any work. Thread.currentThread().interrupt(); break; } readAndExport(); } // Do one last readAndExport before stop. readAndExport(); }
/** * Creates a new {@link IntervalMetricReader}. * * @param metricExporter the {@link MetricExporter} to be called after. * @param metricReader the {@link MetricReader} to be used to read metrics. * @param options the {@link Options} for the new {@link IntervalMetricReader}. * @return a new {@link IntervalMetricReader}. * @since 0.19 */ public static IntervalMetricReader create( MetricExporter metricExporter, MetricReader metricReader, Options options) { checkNotNull(options, "options"); Duration exportInterval = checkNotNull(options.getExportInterval(), "exportInterval"); checkArgument(exportInterval.compareTo(ZERO) > 0, "Export interval must be positive"); return new IntervalMetricReader( new Worker( checkNotNull(metricExporter, "metricExporter"), exportInterval.toMillis(), checkNotNull(metricReader, "metricReader"))); }
/** * Creates a new {@link IntervalMetricReader}. * * @param metricExporter the {@link MetricExporter} to be called after. * @param metricReader the {@link MetricReader} to be used to read metrics. * @param options the {@link Options} for the new {@link IntervalMetricReader}. * @return a new {@link IntervalMetricReader}. * @since 0.19 */ public static IntervalMetricReader create( MetricExporter metricExporter, MetricReader metricReader, Options options) { checkNotNull(options, "options"); Duration exportInterval = checkNotNull(options.getExportInterval(), "exportInterval"); checkArgument(exportInterval.compareTo(ZERO) > 0, "Export interval must be positive"); return new IntervalMetricReader( new Worker( checkNotNull(metricExporter, "metricExporter"), exportInterval.toMillis(), checkNotNull(metricReader, "metricReader"))); }
@Override public void run() { while (true) { try { Thread.sleep(exportInterval); } catch (InterruptedException ie) { // Preserve the interruption status as per guidance and stop doing any work. Thread.currentThread().interrupt(); break; } readAndExport(); } // Do one last readAndExport before stop. readAndExport(); }