Why is bad using own threads inside web application?
Aren't all the servlet request actually a thread in Tomcat?
I can't find a reason why it's so bad solution.
In that way, you manage to have a single and independent application.

Maybe I don't know some thread behaviour in Tomcat...

Jorge.


Allistair Crossley wrote:

myself and ben have suggested the most appropriate methods for doing this. Ben 
mentions WGET http://www.gnu.org/software/wget/wget.html which can be added to 
a *basic* script hooked up to a cron with an interval of whatever you like.

you really ought to get rid of threads and thread sleeps inside web application 
code.

Allistair.



-----Original Message-----
From: Jorge Sopena [mailto:[EMAIL PROTECTED]
Sent: 21 December 2004 17:15
To: Tomcat Users List
Subject: Re: How to run servlet for every 30 minutes in Tomcat 4.1.30


Hi,
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?

Thanks

Jorge


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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]










<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> -------------------------------------------------------
QAS Ltd.
Developers of QuickAddress Software
<a href="http://www.qas.com";>www.qas.com</a>
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT>



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





-- ============================================================== Jorge Sopena Torres SIDSA (Semiconductores Investigación y Diseño, S.A.)

Parque Tecnológico de Madrid
c/ Torres Quevedo, nº 1
28760 TRES CANTOS (Madrid) (SPAIN)

Phone : +34 91 803 5052
Fax:    +34 91 803 9557

e-mail: [EMAIL PROTECTED]
URL: http://www.sidsa.com

==============================================================



Reply via email to