tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jorge Sopena <>
Subject Re: How to run servlet for every 30 minutes in Tomcat 4.1.30
Date Tue, 21 Dec 2004 17:14:30 GMT
I'm having a similar problem in my application.
I've got several servlets called by the users. Every requets save some 
information in DB, that has to be sent to another server later and in a 
compress format.
So I need sth similar toShilpa is asking, a process which runs every  X 
minutes to recover the information and send it to the Server.

My solution to this problem was to implement a "ServletContextListener" 
inside Tomcat.
When Tomcat starts my application the "contextInitialized" method is 
called, and then a thread is started to do the task explained above.
I use "Thread.sleep(step)" to wait for the next execution.

I didn't find anyway to set a timer for a servlet, and I didn't like the 
option of creating an external script .

Any other  suggestions to solver this problem?



Ben Souther wrote:

>On Tue, 2004-12-21 at 11:28, Allistair Crossley wrote:
>>no, and I believe doing so it bad practice. use some OS controlled timer like cron
to issue a HTTP call to your servlet. I once wrote a shell script that calls a http address
on the local machine but cannot remember how ;) if you are using oracle then you can setup
this timer thread inside the database itself. don't add a thread into your web application.
>I concur. It's certainly possible to write a treaded java object that
>fires a command every so often but there would be no point in making
>that object a servlet (servlets exist to answer client requests). 
>It's also, IMHO, more aggravation than it's worth to manage your own
>daemon threads in a webapp.
>It would take all of 2 minutes to write a timer with crontab and wget
>that could call your servlet whenever you want.
>To unsubscribe, e-mail:
>For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message