title: java- Calling a function at every interval
body: <p>I have a program where I am able to insert a filepath and it's corresponding parameters to a table.</p>
  
  <p>After that, I have another function called <code>do_Scan()</code>
  that scans the table and do some processing and indexing to it. </p>
  
  <p>However, I want this function <code>do_Scan()</code> to be run at certain intervals, say every N minutes then it will call this function. The N is definitely configurable.</p>
  
  <p>I was thinking of using a timer class but not quite sure how to implement the configuration. The idea is I create a Timer function that will call the <code>do_Scan</code> method.</p>
  
  <p>The class should be something like this:</p>
  
  <pre><code>public void schedule(TimerTask task,long delay,long period){
  
  }
  </code></pre>
  
  <p>My main method:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  
      Indexing test= new Indexing();
      java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
      // Exception e=e.printStackTrace();
      Scanner scanner = new Scanner(System.in);
      System.out.print("Enter a file path: ");
      System.out.flush();
      String filename = scanner.nextLine();
      File file = new File(filename);
      if(file.exists() &amp;&amp; !file.isDirectory()) {
          test.index_request(filename,"Active",date,date,"");
      }else{
          test.index_request(filename,"Error",date,date,"Some errorCode");
      }
  
      // Call schedule() function 
  }}
  </code></pre>
  
  <p>How do I setup the Timer class so it runs indefinitely for certain interval?</p>