FileDocCategorySizeDatePackage
ScheduleTester.javaAPI DocExample1261Tue May 25 10:18:12 BST 2004com.oreilly.tiger.ch10

ScheduleTester

public class ScheduleTester extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    // Get the scheduler
    ScheduledExecutorService scheduler =
      Executors.newSingleThreadScheduledExecutor();

    // Get a handle, starting now, with a 10 second delay
    final ScheduledFuture<?> timeHandle =
      scheduler.scheduleAtFixedRate(new TimePrinter(System.out), 0, 10, SECONDS);    

    // Schedule the event, and run for 1 hour (60 * 60 seconds)
    scheduler.schedule(new Runnable() {
      public void run() {
        timeHandle.cancel(false);
      }
    }, 60*60, SECONDS);


    /**
     * On some platforms, you'll have to setup this infinite loop to see output
    while (true) { }
     */