Page 1 of 1

About Question enthuware.ocpjp.v8.2.1256 :

Posted: Wed Jul 11, 2018 5:26 am
by 6a617661
The sample code does not shutdown the ScheduledExecutorService thus the application will run indefinitely after the beeps finish.

Suggested edit:

Code: Select all

  
  public void beepForAnHour() {
    final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate( () -> System.out.println( "beep" ), 10, 10, SECONDS );
    scheduler.schedule( () -> {
      beeperHandle.cancel( true );
      scheduler.shutdown();
    }, 60 * 60, SECONDS );
  }