Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-06-2009
Member
 
Join Date: May 2008
Posts: 23
To start a background thread in tomcat

Hi,

I want to know if its possible to run a thread in background as tomcat is started.
The objective is to check my database & particularly some fields of the database to make immediate changes in its values.
I want the thread to run till i shutdown tomcat. Please let me know How to do so?
Reply With Quote
  #2  
Old 17-06-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: To start a background thread in tomcat

Yes you can do it with the help of ServletContextListener.
Its registered in web.xml file in tomcat & will be called on the start & stop of your application. You can create the thread normally like the way you do it in java- ExecutionService.

I hope this helps.
Reply With Quote
  #3  
Old 17-06-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: To start a background thread in tomcat

What you want is a lifecyle Listener. With the new Servlet engine spec (2.3 (?)) you can specify a listener object in your web.xml. The class references must implement the ServletContextListener interface. This has a contextIntialized and a contextDestroyed method. You can have the former launch your thread and the latter close it down (probably by calling interrupt on it).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "To start a background thread in tomcat"
Thread Thread Starter Forum Replies Last Post
Is tomcat application available for Nokia X7? Sheamas Portable Devices 4 10-06-2011 01:02 PM
Synchronize a producer thread and a consumer thread in C# Ayuka Software Development 6 10-11-2010 04:04 AM
Tomcat version 6.x via EasyApache Galimberti Software Development 6 18-06-2010 03:58 AM
Tomcat crashed when used with java Pikachoo Software Development 4 06-03-2009 01:09 PM
Change the Start Menu Background Ehsaan Customize Desktop 2 04-03-2009 02:13 PM


All times are GMT +5.5. The time now is 01:32 PM.