• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.Timer problems  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...
I am using a class called Timer in java.util in my project.
I put my timer delay as 90 sec in a servlet.(periodical)
I am using apache tomcat server.
My server has to handle atleast 10000 requests per 5 hrs.
Timer is giving a lot of problems.
It's stopping after some hours. Then I need to restart from scratch.
How can I solve this problem.
 
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you go into some more detail. What do you mean its stopping after a few hours? It's throwing exceptions, not being run, running too long.

What are you trying to use it for in the first place?
 
Sagar kanchi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

Thanks to show interest.
I'll explain. One of my modules of the project needs a servlet that should be invoked every 90 sec. As long as the server is on the timer should run.
The servlet does a lot of things. It fetcehs an XML file and parses the XML.
I want this as periodical. What's happening is the timer is working fine upto some time(say some 6 hrs) and then stopping. I am unable to understand whether it is stopping or what it is doing. But it is not performing well.
But one thing I am sure about is the Timer is not throwing any Exception.
Now I think you can understand the problem.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar,

Did you find any reasons for this error. I have a similar problem. I have 4 timers and 4 seperate timer tasks that run at scheduled intervals. The timer just dies after a while with no errors at all.

I created 4 seperate timers so that even if one of the timer task takes too long, it would not hog others. The procesing done is surely a little time consuming. The timertasks at times would process for more than 3-4 minutes, while the timer task is scheduled to run evry 2 mins. My take on this is that the task would just run again immediately since the interval has already passed.

Please advice.

Jinesh Parekh
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should happen when you're not keeping up? If task n is not finished before n+1 is scheduled to start should you wait for n to finish or start n+1 in parallel? If you run every minute and the task takes three minutes to run you'll hit this right away.

If you want n+1 to start before n is finished, you can make the TimerTask start the real work on yet another new thread and return. As far as Timer is concerned a single TimerTask runs every 90 seconds. It runs very fast and Timer should fire them off regularly. Timer may be more reliable with long running tasks pushed off to another thread.

With (for example) one minute intervals and three minute run time you'll have as many as three threads running at once. Use a thread pool if you'd like to reduce the overhead of creating and destroying threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!