title: Cancel A Runnable (Java)
body: <p>I am trying to make a repeating runnable only last a certain amount of times, but I can't find a method to cancel the repeating runnable once an integer reaches a certain number.</p>
  
  <pre><code>                Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
                  public void run() {
  
                      Random rand = new Random();
                      int rnum = rand.nextInt(main.allowed.size()) + 1;
  
                      e.getPlayer().getInventory().addItem(main.allowed.get(rnum));
  
                      for(int i = 0; i &gt;= main.getConfig().getInt("SpawnerCase.HowManySpawners"); i++) {
                          // Something here.
                      }
  
                  }
               }, 0L, 0L);
  </code></pre>
  
  <p>Edit:<br>
  I just needed to know how to stop the runnable from inside that for statement. I got that idea from that link (<a href="https://stackoverflow.com/questions/7269294/how-to-stop-a-runnable-scheduled-for-repeated-execution-after-a-certain-number-o">How to stop a Runnable scheduled for repeated execution after a certain number of executions</a>)</p>