title: How to stop a ScheduledExecutorService?
body: <p>The program finishes after nine prints:</p>
  
  <pre><code>class BeeperControl {
  
      private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
  
      public void beep() {
          final Runnable beeper = new Runnable() {
              public void run() {
                  System.out.println("beep");
              }
          };
          final ScheduledFuture&lt;?&gt; beeperHandle = scheduler.scheduleAtFixedRate(
                  beeper, 1, 1, SECONDS);
          scheduler.schedule(new Runnable() {
              public void run() {
                  beeperHandle.cancel(true);
              }
          }, 1 * 9, SECONDS);
      }
  
      public static void main(String[] args) {
          BeeperControl bc = new BeeperControl();
          bc.beep();
      }
  }
  </code></pre>
  
  <p>How to stop a process (i.e. java process in eclipse for example) because it does not stop after a time limit in 9 seconds?</p>