/** * Shuts down the scheduler and calls the close method in the RefreshingLoader. Attempts * to wait for concurrent execution, but does not wait indefinitely. * * @throws IOException If the RefreshingLoader encounters an error on closing. */ public void close() throws IOException { close(false); } }
/** * Static factory constructor. Provides a default name for the thread the scheduler will * run on. * * @param refreshPeriod Configures the refresh rate for the scheduler. * @param timeUnit Specifies the unit of time for the refreshPeriod. * @param refreshingLoader Used to initialize and refresh the cached value. * @param loopController Used to deterministically control refresh cycles during testing. * @param <U> The type that will be cached. * @return A new RefreshingReference. */ public static <U> RefreshingReference<U> create( final Long refreshPeriod, final TimeUnit timeUnit, final RefreshingLoader<U> refreshingLoader, final Optional<LoopController> loopController ) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder() .setNameFormat("refreshing-reference-%d"); return new RefreshingReference<>( refreshPeriod, timeUnit, refreshingLoader, builder, loopController); }
/** * Static factory constructor. Allows the user to pass in a name for the thread * the scheduler will run on. * * @param refreshPeriod Configures the refresh rate for the scheduler. * @param timeUnit Specifies the unit of time for the refreshPeriod. * @param refreshingLoader Used to initialize and refresh the cached value. * @param name The name of the thread the scheduler will run on. * @param loopController Used to deterministically control refresh cycles during testing. * @param <U> The type that will be cached. * @return A new RefreshingReference. */ public static <U> RefreshingReference<U> create( final Long refreshPeriod, final TimeUnit timeUnit, final RefreshingLoader<U> refreshingLoader, final String name, final Optional<LoopController> loopController ) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder() .setNameFormat(name + "-%d"); return new RefreshingReference<>( refreshPeriod, timeUnit, refreshingLoader, builder, loopController); }