Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Spring 3.1 & Tomcat 7.0.23 & task scheduler multiple invocations

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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>

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    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?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    You must be loading it a second time somewhere... You don't construct an applpicationcontext yourself somewhere?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7

    Default

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

  8. #8

    Default

    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

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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?!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I doubt tomcat is the problem, I used this on many occasions without a problem so there must be something weird going on.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •