title: Timer doesn't restart after the wanted time java
body: <p>I have the following code. My problem is that the program is running only once, even though I want it to run every 5 seconds. Can you guide me to my mistake?</p>
  
  <p>Basically the program has to check in a database the last two entries and make a difference between the timestamps. </p>
  
  <p>In the end, it has to give a message to the user, if the time that passed is the needed one or not. This should run continously, but I was only able to make it run once.</p>
  
  <p>Here is the code i have:</p>
  
  <pre><code>java.util.Timer timer = new java.util.Timer();
  
    public TimerChangeButtonBackground() {
       timer.schedule(new TimerTask(){
      public void run() 
          {
  
  
              try {
                   String DB_Connection = "jdbc:sqlserver://127.0.0.1:1433;databaseName=Dizertatie;instance=SQLServer;integratedSecurity=true;";
                  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
                  final Connection conn = DriverManager.getConnection(DB_Connection);
  
  
  
                  Statement state = conn.createStatement();
  
                  ResultSet rs = state.executeQuery("set dateformat dmy; \n" +
  "\n" +
  "SELECT TOP 2 DIFF FROM  DIFF_CT ORDER BY Full_Time_Stamp DESC ");
                  JOptionPanex.getRootFrame().dispose();
                  if(rs.next()){
                      rs.next();
                      String value = rs.getString(1);
                      int difference = Integer.valueOf(value);
  
                      if (difference &lt;= 5){
  
                      ImageIcon icon = new ImageIcon("C:\\Users\\Hory\\Desktop\\likegreen.png");
                  JOptionPanex.showConfirmDialog(
                          null,
                          "Part in target",
                          "In Target", JOptionPanex.OK_CANCEL_OPTION,JOptionPanex.CANCEL_OPTION, icon);
  
                  System.out.printf("target");
                  }
                      else{
  
                       ImageIcon icon2 = new ImageIcon("C:\\Users\\Hory\\Desktop\\likered.png");
                  JOptionPanex.showConfirmDialog(
                              null,
                          "Part NOT in target",
                          "Not in target",JOptionPanex.OK_CANCEL_OPTION,JOptionPanex.CANCEL_OPTION,icon2);
                      System.out.printf("NOtarget");
                      }
  
              }}catch(Exception e){
  
                  System.out.println(e);
              }}},3,5000);  
       `
  </code></pre>