src/share/classes/java/util/concurrent/ScheduledExecutorService.java

Print this page

        

*** 70,97 **** * <h3>Usage Example</h3> * * Here is a class with a method that sets up a ScheduledExecutorService * to beep every ten seconds for an hour: * ! * <pre> * import static java.util.concurrent.TimeUnit.*; * class BeeperControl { * private final ScheduledExecutorService scheduler = * Executors.newScheduledThreadPool(1); * * public void beepForAnHour() { * final Runnable beeper = new Runnable() { * public void run() { System.out.println("beep"); } * }; ! * final ScheduledFuture&lt;?&gt; beeperHandle = * scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); * scheduler.schedule(new Runnable() { * public void run() { beeperHandle.cancel(true); } * }, 60 * 60, SECONDS); * } ! * } ! * </pre> * * @since 1.5 * @author Doug Lea */ public interface ScheduledExecutorService extends ExecutorService { --- 70,96 ---- * <h3>Usage Example</h3> * * Here is a class with a method that sets up a ScheduledExecutorService * to beep every ten seconds for an hour: * ! * <pre> {@code * import static java.util.concurrent.TimeUnit.*; * class BeeperControl { * private final ScheduledExecutorService scheduler = * Executors.newScheduledThreadPool(1); * * public void beepForAnHour() { * final Runnable beeper = new Runnable() { * public void run() { System.out.println("beep"); } * }; ! * final ScheduledFuture<?> beeperHandle = * scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); * scheduler.schedule(new Runnable() { * public void run() { beeperHandle.cancel(true); } * }, 60 * 60, SECONDS); * } ! * }}</pre> * * @since 1.5 * @author Doug Lea */ public interface ScheduledExecutorService extends ExecutorService {