Re: How can I automatically start a servlet in a specific time?
On 11/04/02 7:25, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Ola Kelly, Posso falar em inglês? Se não peça-me devolta e eu faço a tradução. I do exactly this to schedule various tasks such as periodic emails of database generated reports and logging details. If you are using JDK 1.3.x use the Timer and TimerTask. They are very straightforward. A simple demo can be found at: http://java.sun.com/docs/books/tutorial/essential/threads/timer.html I wholeheartedly disagree with the FAQ @ Distributopia. I think servlets are the best way to schedule tasks and they can be packaged with your application on whatever platform that you deploy on. You definitely do not want to run this from cron or any other platform dependent process (even if you did JCrontab exists and is a Java alternative to Cron). The problem with the servlet method I have found is guaranteeing that only one instance of your servlet is instantiated. This is a real problem with Tomcat and you must go to lengths to insure a singleton pattern is not invoked at least twice (once by Tomcat classloader and once by your application classloader). If you find you are having this problem let me know. HTH Steven ///* * VTV Learning Corporation *Los Angeles - Boston - Lisbon * (http://www.vtvLearning.com/) */ -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: How can I automatically start a servlet in a specific time?
Steven Elliott wrote: I wholeheartedly disagree with the FAQ @ Distributopia. I think servlets are the best way to schedule tasks I'd say that's going a bit far. There are obvious drawbacks. and they can be packaged with your application on whatever platform that you deploy on. Using a servlet container as an application server is undeniably appealing, and very convenient. If all you've got is a hammer, etc, etc. I've found that many people fall into the Well, it works fine for me trap. Instead of programming to the spec, they program to whatever servlet container they happen to be using for development work. Sometimes you have to settle for that, but no programmer should aspire to it. At the very least, developers should be aware of potential problems and consciously choose to trade safety for convenience. That's the whole point of the FAQ. I'm curious what you suggest should happen if the user's servlets are swapped out during the time the task should be running. Is the background thread destroyed, in which case the task doesn't run? Or do you leave it running, in which case you've got a resource leak? If you're depending on your particular servlet container never doing something like that, well, that's probably ok. But you may get a nasty shock the next time you upgrade your server. At the very least, people should know that there's a potential problem, and document it for the benefit of future maintainers. -- Christopher St. John [EMAIL PROTECTED] DistribuTopia http://www.distributopia.com -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: How can I automatically start a servlet in a specific time?
Kelly, Boa pergunta... não sei nenhuma maneira directa, mas podes sempre criar um servlet tipo scheduler que arranca automáticamente com o tomcat e que a determinadas horas arranca outros servlets. Carlos -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Kelly Prudente Pereira Analista de Sistemas - NDS [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Fóton® Informática e Serviços Fone: (61) 328 5060 R.: 221 -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: How can I automatically start a servlet in a specific time?
You mean you don't want to load it until a specific time, or you don't want it to respond to requests until a certain time? Ken Carlos Martins wrote: Kelly, Boa pergunta... não sei nenhuma maneira directa, mas podes sempre criar um servlet tipo scheduler que arranca automáticamente com o tomcat e que a determinadas horas arranca outros servlets. Carlos -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Kelly Prudente Pereira Analista de Sistemas - NDS [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Fóton® Informática e Serviços Fone: (61) 328 5060 R.: 221 -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: How can I automatically start a servlet in a specific time?
I'd imagine that you'll need to create a start on load servlet that has it's on internal scheduler for starting other tasks. Even if tomcat had something to do what you're looking for I don't think it'd work in any other jsp container. Then again if you're on a unix box you could just use cron... --mikej -=- mike jackson [EMAIL PROTECTED] -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 10, 2002 3:20 PM To: 'Tomcat Users List' Subject: RES: How can I automatically start a servlet in a specific time? Yes Ken, I mean I don't want to load it until a specific time. I need to load it to do a specific job at a certain time. Do you know how can I do this? -Mensagem original- De: Ken Anderson [mailto:[EMAIL PROTECTED]] Enviada em: quarta-feira, 10 de abril de 2002 19:19 Para: Tomcat Users List Assunto: Re: How can I automatically start a servlet in a specific time? You mean you don't want to load it until a specific time, or you don't want it to respond to requests until a certain time? Ken Carlos Martins wrote: Kelly, Boa pergunta... não sei nenhuma maneira directa, mas podes sempre criar um servlet tipo scheduler que arranca automáticamente com o tomcat e que a determinadas horas arranca outros servlets. Carlos -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Kelly Prudente Pereira Analista de Sistemas - NDS [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Fóton® Informática e Serviços Fone: (61) 328 5060 R.: 221 -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: How can I automatically start a servlet in a specific time?
nope, nunca fiz... tens a certeza que é um servlet que queres correr a determinada hora? É que um servlet é uma classe específica para respoder a pedidos remotos (por http). Se o programa que queres correr a determinadas horas não tem nada a ver com pedidos de http, então podes fazer uma classe normal de java e corre-la a determinadas horas usando o scheduler do windows ou o cron to linux. -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:16 To: 'Tomcat Users List' Subject: RES: How can I automatically start a servlet in a specific time? Não sei bem se entendi. Eu uso o load-on-startup para carregar uma servlet e esta fica responsável por chamar outra num determinado horário? Já fez isso? Obrigada por responder. -Mensagem original- De: Carlos Martins [mailto:[EMAIL PROTECTED]] Enviada em: quarta-feira, 10 de abril de 2002 19:04 Para: Tomcat Users List Assunto: RE: How can I automatically start a servlet in a specific time? Kelly, Boa pergunta... não sei nenhuma maneira directa, mas podes sempre criar um servlet tipo scheduler que arranca automáticamente com o tomcat e que a determinadas horas arranca outros servlets. Carlos -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Kelly Prudente Pereira Analista de Sistemas - NDS [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Fóton® Informática e Serviços Fone: (61) 328 5060 R.: 221 -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: How can I automatically start a servlet in a specific time?
How about using some kind of command line driven web URL grabber (e.g. webgrab for UNIX, or write your own java version) launched at the appropriate time (via cron or Task Scheduler) which asks for a URL which will cause the servlet to load and do it's thing. Of course, you need to be reasonably sure that someone won't unexpectedly request that URL at some other time. Jeff - Original Message - From: Kelly Prudente Pereira [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Wednesday, April 10, 2002 5:20 PM Subject: RES: How can I automatically start a servlet in a specific time? Yes Ken, I mean I don't want to load it until a specific time. I need to load it to do a specific job at a certain time. Do you know how can I do this? -Mensagem original- De: Ken Anderson [mailto:[EMAIL PROTECTED]] Enviada em: quarta-feira, 10 de abril de 2002 19:19 Para: Tomcat Users List Assunto: Re: How can I automatically start a servlet in a specific time? You mean you don't want to load it until a specific time, or you don't want it to respond to requests until a certain time? Ken Carlos Martins wrote: Kelly, Boa pergunta... não sei nenhuma maneira directa, mas podes sempre criar um servlet tipo scheduler que arranca automáticamente com o tomcat e que a determinadas horas arranca outros servlets. Carlos -Original Message- From: Kelly Prudente Pereira [mailto:[EMAIL PROTECTED]] Sent: quarta-feira, 10 de Abril de 2002 23:04 To: '[EMAIL PROTECTED]' Subject: How can I automatically start a servlet in a specific time? Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Thanks in advanced, Kelly Prudente Pereira Analista de Sistemas - NDS [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Fóton® Informática e Serviços Fone: (61) 328 5060 R.: 221 -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: How can I automatically start a servlet in a specific time?
Can anyone answer my question? How can I automatically start a servlet in a specific time? For example: at midnight. I don't want to start it when I start my webserver. Create an intialisation servlet who's init() method is called when the web application comes into scope. In the init() method spawn a new thread and sleep until the apropriate time and then call whatever method you need to execute at that time. You should be able to set up multiple actions on one sleeping thread if required. Use a timer object or some other helper to manage your sleeping. Be sure also to have a destroy method that shuts down the sleeping thread, otherwise you thread will keep running when you remove your web application and the only way to get rid of it will be to restart the whole server. this code runs periodically, you'll have to do something slightly different to do something at a particular time of day /** * Called by the container when the application comes into scope (ie on application load) * * Starts the memory logger */ public void init() { if (timer != null) { WebLogger.log(timer not null aborting MemoryDaemon start); return; } timer = new Timer(true); timer.schedule(new DaemonTask(), 0, DELAY_MINS * SECS_MIN * MILLIS_MIN); WebLogger.log(initialised MemoryDaemon); } /** * Called by the container when the servlet goes out of scope (ie on application reload) */ public void destroy() { WebLogger.log(Shutting down MemoryDaemon); timer.cancel(); } -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]