title: What can be the reasons for a TimerTask to stop running in a Tomcat Servlet
body: <p>I suspect an exception could make the TimerTask stop running in which case I most likely need a second timetask to monitor that the first is still running?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Thanks for the answers. I had inherited this code so a bit ignorant...</p>
  
  <p>I just saw that if I throw an uncaught exception in my job the TimerThread ceases to run forever. </p>
  
  <p>Run method of <code>TimerThread</code> showed that if an exception is thrown, my scheduled thread never runs again.</p>
  
  <pre><code>public void run() {
      try {
          mainLoop();
      } finally {
          // Someone killed this Thread, behave as if Timer cancelled
          synchronized(queue) {
              newTasksMayBeScheduled = false;
              queue.clear();  // Eliminate obsolete references
          }
      }
  }
  </code></pre>
  
  <p>The end of the stacktrace will be:</p>
  
  <pre><code>at java.util.TimerThread.mainLoop(Timer.java:512)
  at java.util.TimerThread.run(Timer.java:462)
  </code></pre>
  
  <p>So temp solution is to catch EVERYTHING... longer term solution is to move to better scheduling as BalusC states.</p>