title: Best way to create a background thread in java
body: <p>What is the best way to create a background thread that will run every 15 minutes to get the data from the database?</p>
  
  <p>Below is the code I have which will work fine I guess in production but is there any other way better that I have or something that I should be aware of?</p>
  
  <pre><code>private static void checkDatabaseEveryXMinutes() {
      new Thread() {
          public void run() {
              while (true) {
                  try {
                      Thread.sleep(checkingAfterEveryXMinutes);
                      getDataFromDatabase();
                  } catch (InterruptedException ex) {
                      //log here
                  } catch (Exception e) {
                      //log here
                  }
              }
          }
      }.start();
  }
  </code></pre>
  
  <p>Is there any disadvantage in using the above code. And how does ScheduledExecutorService compares with TimerTask?</p>
  
  <p>Which way is better?</p>
  
  <p>Any example basis on my code will be appreciated on this if there are any better approach.</p>