Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.0 scheduled-tasks config prevent tomcat from shutting down Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.0 scheduled-tasks config prevent tomcat from shutting down

    As mentioned in my comment on Spring Blog http://blog.springsource.com/2010/01...in-spring-3-0/ I migrated my old code to use the new task scheduling infrastructure. However, after deploying it to Tomcat, the Tomcat can no longer be shut down - I must kill the process to shut it down every time.
    Now I've replaced the real task bean with dummy one, but the problem is still there. I have such entry in application context config:
    <task:scheduled-tasks>
    <task:scheduled ref="foo" method="sayfoo" cron="0 45 23 * * ?"/><!--fire at 23:45 every day-->
    </task:scheduled-tasks>
    <bean id="foo" class="example.NewClass" />

    The NewClass has only one method sayfoo which does nothing.
    When I deploy it to Tomcat, I'm not able to stop the server. When I remove the <task:scheduled-tasks> section, everything works correctly again.

  • #2
    If you create and close the ApplicationContext properly the LifecycleProcessor should handle the shutdown for you. How did you create the context (best practice would be to use a ContextLoaderListener and/or a DispatcherServlet)? How did you attempt to shutdown Tomcat?

    Something to try: whack up the debug level and look for a log during shutdown like this:

    Code:
    DEBUG [org.springframework.beans.factory.support.DisposableBeanAdapter] - <Invoking destroy() on bean with name 'org.springframework.scheduling.config.ScheduledTaskRegistrar#0'>
    If you don't see that then the context isn't closing. If you do then there may be something more interesting going on.

    Something else to try: load the same application context in a unit test, and verify the behaviour. Post the test if it doesn't shutdown cleanly.

    Comment


    • #3
      We use org.springframework.web.context.ContextLoaderListe ner for creating the context.
      We also use the context in tests, and it runs and shuts down properly (well, using the scheduler in most tests is pointless in fact... it should be factored into separate config files).
      I will try to look at debug messages in a free time.

      Comment


      • #4
        Are the threads in scheduler set to run as non daemon?

        Comment


        • #5
          In addition to what Amit suggested, could you just take a stacktrace when Tomcat is shutting down and starting to look unresponsive. See this article on how to create on (plus other utilities for JDK 6): http://java.sun.com/javase/6/webnote...scr.html#gbmps

          Comment


          • #6
            Hi grzegorzborkowski.

            Simply you should add scheduler for your task. For example:

            <task:scheduled-tasks scheduler="myscheduler">
            <task:scheduled ref="foo" method="foomethod" cron="..." />
            </task:scheduled-tasks>

            <task:scheduler id="myscheduler" pool-size="10"/>

            How I understand only scheduler (not task ) has mark of disposable bean for destroying executable thread.

            Comment


            • #7
              Originally posted by Vladimir.Aleshkevich View Post
              Hi grzegorzborkowski.

              Simply you should add scheduler for your task. For example:

              <task:scheduled-tasks scheduler="myscheduler">
              <task:scheduled ref="foo" method="foomethod" cron="..." />
              </task:scheduled-tasks>

              <task:scheduler id="myscheduler" pool-size="10"/>

              How I understand only scheduler (not task ) has mark of disposable bean for destroying executable thread.
              This solution worked for me. I was having the same issue. Thanks!

              Comment

              Working...
              X