title: Java Run Method every 30th second of a minute
body: <p>I have the following while loop:</p>
  <pre><code>while (keepRunning) {
  
      if (!once) {
  
          // Run a test method every 30th second
  
          // Run the new calculations from the database
          new CalculatorDriver().run();
  
          // Wait in the while loop for 1 second before looping again
          TimeUnit.SECONDS.sleep(1);
      }
  }
  </code></pre>
  <p>This while loop will loop every second through the code, but now I want to run a method called: <code>getNewCalculations()</code> every 30th second of a minute, so for example, the method needs to run at:</p>
  <ul>
  <li>18:26:30</li>
  <li>18:27:30</li>
  <li>18:28:30</li>
  </ul>
  <p>I already found a way to run a method every x seconds:</p>
  <pre><code>Timer timer = new Timer(); 
  timer.schedule(new Task(), 60 * 1000);
  </code></pre>
  <p>But I also need to start it at a specific point. In C# someone tried this to run a script every 30th and every 0th second: <a href="https://stackoverflow.com/a/53846390/10673107">https://stackoverflow.com/a/53846390/10673107</a>.</p>
  <p>I could just add an <code>if</code> where the second can't be equal to 0, but I was wondering if there was a better way to do this.</p>
  <p>How can I run it only in the 30th second?</p>