Obtaining reference to servlet that is instantiated by tomcat on server start up
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dave_Hemingway
Posted On:   Monday, April 1, 2002 04:04 AM

I have a servlet that acts as a taskscheduler. Basicaly it is a thread that sleeps for an hour then checks to see if any tasks are scheduled to be done. This servlet is instantiated by tomcat on server start. It is setup in the web.xml as follows: startServlet StartServlet However I want to gain a reference to this instance from within my web application so I may run various tests on the thread to ensure that it is still running. For if the thread dies due to an external exception or otherwise, my web application needs a way to restart it. Any ideas or suggestions would be much appreciated. Thanks in advance. regards, Dave    More>>

I have a servlet that acts as a taskscheduler. Basicaly it is a thread that sleeps for an hour then checks to see if any tasks are scheduled to be done. This servlet is instantiated by tomcat on server start. It is setup in the web.xml as follows:

			

startServlet
StartServlet



However I want to gain a reference to this instance from within my web application so I may run various tests on the thread to ensure that it is still running. For if the thread dies due to an external exception or otherwise, my web application needs a way to restart it. Any ideas or suggestions would be much appreciated. Thanks in advance.


regards,

Dave    <<Less

Re: Obtaining reference to servlet that is instantiated by tomcat on server start up

Posted By:   Mathias_Neuhaus  
Posted On:   Thursday, April 4, 2002 03:48 AM

Hi Dave,

why bother to start a scheduler at server startup with no tasks to execute?

Start the scheduler, when the first task is to be scheduled (from a request to a servlet I understand), and insert a reference to it in application scope.

bis die Tage...
  Mathias

Re: Obtaining reference to servlet that is instantiated by tomcat on server start up

Posted By:   Bozidar_Dangubic  
Posted On:   Monday, April 1, 2002 06:24 AM

servlet is not just any plain 'ol java class. it is a request-response mechanism. so you are not to get a reference to the servlet. a reference to the servlet makes no sense given what the servlets are designed to do. what you could do is in the web.xml, define url-mapping for the servlet startServlet and then send it a request, either from the client side or from some other component using UrlConnection. that is the only thing you should be doing with the servlets - sending it a request and getting a response. no reference to servlets from other components are necessary or desireable.
About | Sitemap | Contact