This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java util Timer terminates itself  RSS feed

sram bahl
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using java.util.Timer class to monitor some of my application process and report to a controller. This monitor runs 24 X 7 at a fixed polling interval. What i notice is after 5-6 days the monitor terminates itself. My actual code has two monitors (SelfMonitor and AppMonitor), both running at different intervals. What could be the problem. If i add a shutdownhook is it possible to ascertain what caused the termination ? I do not call cancel anywhere on my code.

public class TimerProblem {

class SelfMonitor extends TimerTask {
* Send SaJvmMonitor heartbeat to the controller every 10 mins.
public void run() {"SaJvmMonitor is Alive...");
try {
conn = (HttpURLConnection) controlUrl.openConnection();
PrintWriter out = new PrintWriter(conn.getOutputStream());
log.debug("connected to controller " + conn);
"SaJvm Status = "
+ URLEncoder.encode("SaJvmMonitor is Alive..."));
int code = conn.getResponseCode();
} catch (Exception ex) {
"Unable to establish connection with the Controller "
+ controller);;
} finally {
out = null; //release PrintWriter for GC


public static void main(String[] ar) {
timer = new Timer();
timer.schedule(new AppMonitor(), 0, pulseRate * 60 * 1000);
timer.schedule(new SelfMonitor(), 0, pulseRate * 3 * 60 * 1000);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!