Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.1 & Tomcat 7.0.23 & task scheduler multiple invocations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.1 & Tomcat 7.0.23 & task scheduler multiple invocations

    Hi every one,

    my spring.xml looks like
    Code:
    <task:scheduler id="feedServiceScheduler"  pool-size="10"/>
    <task:scheduled-tasks scheduler="feedServiceScheduler">        
        <task:scheduled ref="feedService" method="testMethod" cron="0 50 11 * * *" />
    </task:scheduled-tasks>
    I expect method "testMethod" to be invoked on object "feedService" at 11:50 every day of the year
    For some reason testMethod is invoked twice and I just can't find a solution to the problem.

    "feedService" bean is nothing fancy, just a simple POJO and test method prints out a message.

    Any help about what I might be doing wrong would be great.

    Thanks //janskyview

  • #2
    My guess you are loading the configuration twice.. You are either importing the xml containing this declaration or explicitly defining the xml for both the ContextLoaderListener and DispatcherServlet.

    Comment


    • #3
      Hi,

      thank you very much for your answer, this is how my web.xml looks like:


      ---------------------------------------------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <!-- Application Name & Description -->
      <display-name>Amazon Feed</display-name>
      <description>Amazon Feed Processor</description>

      <!-- Welcome Files -->
      <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>

      <!-- Spring Context Loader Listener & Configuration files
      <listener>
      <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
      </listener>
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
      /WEB-INF/settings/spring.xml
      /WEB-INF/settings/spring-security.xml
      </param-value>
      </context-param>
      -->

      <!-- Spring Security Filter & Mapping
      <filter>
      <filter-name>springSecurityFilterChain</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFil terProxy</filter-class>
      </filter>

      <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      -->
      <!-- Session events publisher -->
      <listener>
      <listener-class>org.springframework.security.web.session.Htt pSessionEventPublisher</listener-class>
      </listener>



      <!-- SiteMesh Filter & Mapping -->
      <filter>
      <filter-name>SiteMesh Filter</filter-name>
      <filter-class>com.opensymphony.module.sitemesh.filter.Page Filter</filter-class>
      <init-param>
      <param-name>configLocation</param-name>
      <param-value>/WEB-INF/settings/sitemesh-decorators.xml</param-value>
      </init-param>
      </filter>
      <filter-mapping>
      <filter-name>SiteMesh Filter</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>ERROR</dispatcher>
      </filter-mapping>


      <!-- Spring Servlet & Mapping -->
      <servlet>
      <servlet-name>springServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
      <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/settings/spring.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
      <servlet-name>springServlet</servlet-name>
      <url-pattern>/spring/*</url-pattern>
      </servlet-mapping>

      <!-- Log4J Configuration Listener & Configuration File -->
      <listener>
      <listener-class>org.springframework.web.util.Log4jConfigList ener</listener-class>
      </listener>
      <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/classes/log4j.properties</param-value>
      </context-param>



      <!-- Error Pages -->
      <error-page>
      <error-code>404</error-code>
      <location>/errors/pagenotfound.jsp</location>
      </error-page>

      <error-page>
      <error-code>403</error-code>
      <location>/errors/accessdenied.jsp</location>
      </error-page>

      </web-app>

      ----------------------------------------------------------------------------------------------------------------------------

      Comment


      • #4
        Please use code tags... As I stated you are loading the files twice... Both the CLL and DS are loading the spring.xml... Simply don't do that. The DS should only have to load the web related stuff, the CLL the application and infrastructure beans.

        Comment


        • #5
          Hi,

          CCL is commented out actually, right now for the sake of clarity I stripped out the web.xml file of everything else and now looks
          like:

          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
          	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
          
           	
          	
          	<!-- Spring Servlet &  Mapping -->
          	<servlet>
          		<servlet-name>springServlet</servlet-name>
          		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          		<init-param>
          			<param-name>contextConfigLocation</param-name>
          			<param-value>/WEB-INF/settings/spring.xml</param-value>
          		</init-param>
          		<load-on-startup>1</load-on-startup>
          	</servlet>		
          	<servlet-mapping>
          		<servlet-name>springServlet</servlet-name>
          		<url-pattern>/spring/*</url-pattern>
          	</servlet-mapping>
          
          	<!-- Log4J Configuration Listener  & Configuration File -->
          	<listener>
          		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
          	</listener>
          	<context-param>
          		<param-name>log4jConfigLocation</param-name>
          		<param-value>/WEB-INF/classes/log4j.properties</param-value>
          	</context-param>
          
          
          </web-app>


          but same result...any direction you would to go search where the problem is?

          Comment


          • #6
            You must be loading it a second time somewhere... You don't construct an applpicationcontext yourself somewhere?

            Comment


            • #7
              actually no...I've searched everywhere maybe a tomcat issue?

              Comment


              • #8
                Ok, found the problem, now trying to aim at some workaround.

                Tomcat is the problem.

                I've tried to use quartz via spring.xml and as in task:scheduler I had the same multiple invocations problem.
                So I decided to launch the scheduler via code and had the following results:

                1) Using tomcat the same task gets called multiple times
                2) Executing the same task via main method with no application server involment works perfect.

                It is difficult at this point to choose which path to follow, I'm thinking about using quartz servlet, that way (I hope) there's some
                memory usage optimization....anyway, any help would be greatly appreciated at this point.

                thank you

                Comment


                • #9
                  I suggest you switch on debug logging and see when and where it is being constructed twice... Also this is the only thing you have you don't have a scheduled annotation somewhere in your code?!

                  Comment


                  • #10
                    I doubt tomcat is the problem, I used this on many occasions without a problem so there must be something weird going on.

                    Comment


                    • #11
                      I'll try that thanks. As far as annotations I guess I'll use them when the basics of scheduling are ok

                      Comment

                      Working...
                      X