0

Possible Duplicate:
How can I shutdown Spring task executor/scheduler pools before all other beans in the web app are destroyed?

I am creating a website involving sessions and need to create a separate thread to run some tasks once a day. I also need it to shutdown when tomcat does and heard I could use the following code within web.xml:

    <listener>
        <listener-class>Thread</listener-class>
    </listener>

The Thread class being referenced simply implements Runnable and performs various sleeps once ran. Does this code cater for the creation and destruction of such threads or are there better ways of doing such things?

Jon

Community
  • 1
  • 1
Jon
  • 3,174
  • 11
  • 39
  • 57
  • If you're using Spring, then using [Spring scheduling facilities](http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html) is a much more fluent and simpler way to do so. – nobeh Jul 17 '12 at 09:49
  • Thanks nobeh, but I can't see any options for executing the thread when the site is created. Same for on destruction. Trigger implementations look alright, but again they just seem to be generated with a set routine and not using an actual trigger on creation. Is there a way of passing a trigger to the thread that I am missing? – Jon Jul 17 '12 at 10:03
  • Is there any specific reason you need to manage the threads? – nobeh Jul 17 '12 at 10:04
  • I need a thread to be created when the site is, so that it can run a timed task every day. However, when the site shuts down, I don't want the thread to simply die off, I would like it to shut down more efficiently. It needs to shut down so that there are always no more than one running. – Jon Jul 17 '12 at 10:08
  • 1
    Suggest reading http://stackoverflow.com/a/6603443/248082 and http://stackoverflow.com/a/3994892/248082 – nobeh Jul 17 '12 at 10:19
  • Thanks nobeh your first link seems to have done the trick nicely – Jon Jul 17 '12 at 13:29

0 Answers0