Home arrow static arrow Java Programming [Archive] - letting tomcat start a class
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - letting tomcat start a class
This topic has 5 replies on 1 page.

Posts:3,183
Registered: 10.09.03
letting tomcat start a class  
Aug 4, 2004 6:19 AM



 
I have a class which runs as a daemon thread. I want this class to start right after tomcat boots. Is there a way to make Tomcat execute a class on startup?

The only way I can think of is creating a simple class which fetches a JSP that starts the thread. If anyone knows a better solution, I would be grateful.
 

Posts:96
Registered: 8/4/97
Re: letting tomcat start a class  
Aug 4, 2004 6:22 AM (reply 1 of 5)



 
if i remember correctly, tomcat uses a simple BAT file to start. Can't you just put your class in there? (of course you need a simple main() to kick off the thread.
 

Posts:3,183
Registered: 10.09.03
Re: letting tomcat start a class  
Aug 4, 2004 6:31 AM (reply 2 of 5)



 
I don't think so since it's a daemon thread. So if I start the thread from there, the main executes, finishes and the thread stops running as well. That's why I need tomcat to start the class.
 

Posts:4,496
Registered: 19/06/02
Re: letting tomcat start a class  
Aug 4, 2004 6:36 AM (reply 3 of 5)



 
If you want to run something on startup you can do it via a web.xml file:
   <servlet>      <servlet-name>StartupServlet</servlet-name>      <servlet-class>xxx.xxx.xxx.xxx.StartupServlet</servlet-class>      <init-param>	 <param-name>name</param-name>	 <param-value>value</param-value>      </init-param>      <init-param>	 <param-name>name2</param-name>	 <param-value>value2</param-value>      </init-param>      <load-on-startup>1</load-on-startup>	   </servlet>  
 

Posts:19,725
Registered: 9/26/01
Re: letting tomcat start a class  
Aug 4, 2004 6:39 AM (reply 4 of 5)



 
If you want to run something on startup you can do it
via a web.xml file:
Plus the fact that doing it more along the lines of this way makes it machine independent. You wouldn't want to change everyone's startup script if this is going to be installed on machines other than your own.
 

Posts:3,183
Registered: 10.09.03
Re: letting tomcat start a class  
Aug 4, 2004 6:48 AM (reply 5 of 5)



 
Great, thanks a lot you guys.
 
This topic has 5 replies on 1 page.