title: Making code that runs automatically within a given interval
body: <p>I have a few questions about having code that runs automatically within a given interval. I'm programming a kind of game mode where it checks if the players have killed all the monsters in the map (I have my methods for these). I was wondering what's the best way to program this check? I've looked up ways where a person made a ScheduledExecutorService during a class constructor....</p>
  
  <pre><code>private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
  </code></pre>
  
  <p>But I saw online where people used </p>
  
  <pre><code>static void main(String[] args) {
  </code></pre>
  
  <p>And a run method to do the checks. Which would be better? I'm simply wanting to have a check that runs every few or so seconds that sees if the player has cleared the map, and if he or she has, then to progress to the next stage.</p>