title: Working around the "variable might not have been initialized" error
body: <pre><code>public final void sendAdvertisement(final Advertisement advertisment, int delay, final int repetitions){
      final ScheduledFuture exec = executor.scheduleAtFixedRate( //&lt;&lt; initialized on this line
          new Runnable(){
              int totalSends = 0;
              public void run(){
                  //do stuff here
  
                  if(++totalSends &gt;= repetitions) exec.cancel(true); //&lt;&lt; here is says exec might not be initialized
              }
          },
      0, delay, TimeUnit.MILLISECONDS);
  }
  </code></pre>
  
  <p>If this isn't possible, could you suggest a better way to do this? I couldn't find a method for it in ScheduledThreadPoolExecutor. basically what I'm trying to do is make this code be run 3 times then cancel the "timer." I could probably use Swing Timer, but I don't want to since its used for other stuff.</p>
  
  <p>It says in the comments, but this is the error:</p>
  
  <pre><code>%PATH%Discovery.java:148: variable exec might not have been initialized
                  if(++totalSends &gt;= repetitions) exec.cancel(true);
  </code></pre>