Results 1 to 8 of 8

Thread: Help using Quartz scheduler in the Spring framework.

  1. #1
    Join Date
    Jun 2008
    Posts
    10

    Default Help using Quartz scheduler in the Spring framework.

    Hello,

    I have a requirement in my project to generate reports in an asynchronous fashion. All the requests for generation of reports are put into a queue with a request handler polling the queue at a predefined interval. If no request is being processed currently and there is a request waiting in the queue then it is taken up for processing. I am trying to use the Quartz scheduler in the Spring framework for scheduling the polling of the queue. This is the Spring xml :-

    Code:
        	<bean id="reportsQueue" class="reports.ReportsQueue"/>
        	
        	<!-- Define the Job Bean that will be executed. The bean is named in the jobClass property. //-->
        	<bean name="reportsGenerationJob" class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="jobClass" ref="reportsQueue"/>
            </bean>
            
            <!-- Associate the Job Bean with a Trigger. Triggers define when a job is executed. //-->
            <bean id="scheduleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
                <property name="jobDetail" ref="reportsGenerationJob"/>
                <property name="startDelay" value="1000"/>
                <property name="repeatInterval" value="1000"/>
            </bean>
            
            <!-- A list of Triggers to be scheduled and executed by Quartz //-->
            <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="triggers">
                    <list>
                        <ref bean="scheduleTrigger"/>
                    </list>
                </property>
            </bean>


    I found something similar using google. The problem here is that the executeInternal() method of the ReportsQueue bean is not being executed at all. Has anybody worked with something similar?

    Cheers,
    Raj.

  2. #2
    Join Date
    Jun 2008
    Posts
    10

    Default Version issue?

    Hi,

    I think the whole issue was caused by a version incompatibility. I skipped the Quartz scheduler part and used the Timer and it worked fine. Now moving on to weaving of another layer into the application.

    Thanks,
    Raj.

  3. #3
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    If you use Java 5+, you can also go for a BlockingQueue in combination with an Executor. It provides more control. One of the many advantages of using an executor instead of a timer is that you don't need to wait till the time has elapsed. So as soon as there is something new to process, you can process it. Depending on the scenario this could be an advantage or totally uninteresting.

  4. #4
    Join Date
    Jun 2008
    Posts
    10

    Default Good suggestion

    Hi,

    What you mentioned does sound really interesting as the initial requirement was that sorts. But now that the scheduling part is working I need to move on and change a smart part of the functionality. I might have to modify this later on but that mainly includes changing the XML, I feel.

    The reports being generated were displayed to the user (on the screen) in a synchronous fashion. Since there is no point in displaying it as the whole operation now occurs offline, I have to send out an e-mail containing the generated report.

    For this I have been thinking of using weaving and taking advantage of the AOP framework rather than modifying the existing code. So using JdkRegexpMethodPointcut, DefaultPointcutAdvisor and DefaultPointcutAdvisor now. My 'after returning advice' is not being executed now. The xml I am using for this is as below:-
    Code:
    <bean id="reportsPointcut"
    			class="org.springframework.aop.support.JdkRegexpMethodPointcut">
    		<property name="pattern" value=".*run" />
    	</bean>
    	
    	<bean id="reportsAdvisor"
    			class="org.springframework.aop.support.DefaultPointcutAdvisor"
    			lazy-init="false">
    		<property name="advice" ref="reportsQueue" />
    		<property name="pointcut" ref="reportsPointcut" />
    	</bean>
    	
    	<bean id="report"
    			class="org.springframework.aop.framework.DefaultPointcutAdvisor">
    		<property name="target" ref="reportsQueue" />
    		<property name="interceptorNames" value="reportsAdvisor" />
    		<property name="proxyInterfaces"
    		 	value="org.springframework.aop.AfterReturningAdvice" />
    	</bean>
    Is there anything I am missing?

    Cheers,
    Raj.

  5. #5
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by jarkalam View Post
    Hi,

    What you mentioned does sound really interesting as the initial requirement was that sorts. But now that the scheduling part is working I need to move on and change a smart part of the functionality. I might have to modify this later on but that mainly includes changing the XML, I feel.
    That is how my like my concurrency I also try to extract the mechanism out of the code. In most cases I can hook up any engine (the threads) to some axle (some method).

    The reports being generated were displayed to the user (on the screen) in a synchronous fashion. Since there is no point in displaying it as the whole operation now occurs offline, I have to send out an e-mail containing the generated report.

    For this I have been thinking of using weaving and taking advantage of the AOP framework rather than modifying the existing code. So using JdkRegexpMethodPointcut, DefaultPointcutAdvisor and DefaultPointcutAdvisor now. My 'after returning advice' is not being executed now. The xml I am using for this is as below:-
    Code:
    <bean id="reportsPointcut"
    			class="org.springframework.aop.support.JdkRegexpMethodPointcut">
    		<property name="pattern" value=".*run" />
    	</bean>
    	
    	<bean id="reportsAdvisor"
    			class="org.springframework.aop.support.DefaultPointcutAdvisor"
    			lazy-init="false">
    		<property name="advice" ref="reportsQueue" />
    		<property name="pointcut" ref="reportsPointcut" />
    	</bean>
    	
    	<bean id="report"
    			class="org.springframework.aop.framework.DefaultPointcutAdvisor">
    		<property name="target" ref="reportsQueue" />
    		<property name="interceptorNames" value="reportsAdvisor" />
    		<property name="proxyInterfaces"
    		 	value="org.springframework.aop.AfterReturningAdvice" />
    	</bean>
    Is there anything I am missing?

    Cheers,
    Raj.
    Personally I don't like this approach. Asynchronous calls should be a design issue and not an implementation detail. One of the differences between a synchronous call and an asynchronous call is that an asynchronous call doesn't need to throw a 'generate report error'. But on the other hand, it could throw an 'rejected execution exception' when the system shuts down for example of when there are already too many reports being generated.

    So even though technology makes it possible to make calls asynchronously transparently, it doesn't mean that you should

    http://pveentjer.wordpress.com/2006/...tation-detail/

  6. #6
    Join Date
    Jun 2008
    Posts
    10

    Thumbs up

    Hello,

    I agree the asynchronous part is a design issue but the problem the client is facing right now is that the data contained in most of these reports is humongous. Most report generation hits 10 to 13 database tables and picks up data from them. So you can assume how slow the whole operation is going to be. On an average its takes 7 to 8 minutes and asking anybody to wait so long is not a brilliant idea, right?

    So as part of a solution we were thinking of floating the idea of the offline operation and take it forward if the client likes the idea. Before we propose something we would like to be sure it can be achieved. Spring framework is pretty good and though there are so many features offered we want to get a working sample done so as to give the client a demo.

    As of now I am moving forward with the R&D as I find it very interesting. I am getting a layer added for now so as to incorporate the necessary functionality. Thanks for the valuable suggestions.

    Cheers,
    Raj.

  7. #7
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by jarkalam View Post
    Hello,

    I agree the asynchronous part is a design issue but the problem the client is facing right now is that the data contained in most of these reports is humongous. Most report generation hits 10 to 13 database tables and picks up data from them. So you can assume how slow the whole operation is going to be. On an average its takes 7 to 8 minutes and asking anybody to wait so long is not a brilliant idea, right?
    Asynchronous calls are not a bad thing. The only bad thing is to make 'synchronous' calls transparently asynchronous.

    Good luck with your project!

  8. #8
    Join Date
    Jun 2008
    Posts
    10

    Question

    I am now facing a problem instantiating an instance of the ProxyFactoryBean. This is my sample XML :-
    Code:
    <bean id="businesslogicbean"
       class="org.springframework.aop.framework.ProxyFactoryBean">
          <property name="proxyInterfaces">
             <value>SendMail</value>
          </property>
          <property name="proxyTargetClass" value="true" />
          <property name="target">
             <ref local="reportsQueue"/>
          </property>
          <property name="interceptorNames">
             <list>
                <value>theTracingAfterAdvisor</value>
             </list>
             </property>
       </bean>
    	
    	<!-- Advisor pointcut definition for after advice -->
       <bean id="theTracingAfterAdvisor"
          	class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
          <property name="advice">
             <ref local="theTracingAfterAdvice"/>
          </property>
          <property name="pattern">
             <value>.*Mail</value>
          </property>
       </bean>
       
        <bean id="theTracingAfterAdvice" class="ReportsQueue" />
    And this is starting stack trace for the error that is being thrown when I start up the server :-
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'businesslogicbean' defined in ServletContext resource [/WEB-INF/smart-reports.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.framework.ProxyFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.framework.ProxyFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
    Beacue of the metion of the org.objectweb.asm.ClassWriter I got asm-2005-01-27.jar in my lib folder and it does have ClassWriter.class

    Any suggestions?

    Cheers,
    Raj.

Posting Permissions

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