Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Quartz scheduler problem need help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz scheduler problem need help

    We are having some problem with the Quartz scheduler and opensessionviewFilter
    The configuration is descibed below
    <bean name="notificationSchedulerBean" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass">
    <value>core.service.scheduler.NotificationSchedule r</value>
    </property>
    <property name="jobDataAsMap">
    <map>
    <entry key="timeout">
    <value>5</value>
    </entry>
    <entry key="schedulerJobDetailsDAO">
    <ref bean="SchedulerJobDetailsDAO" />
    </entry>
    <entry key="applicationSettingDAO">
    <ref bean="ApplicationSettingDAO" />
    </entry>
    <entry key="mailerServiceManager">
    <ref bean="mailerServiceManager" />
    </entry>
    <entry key="repeatInterval">
    <!-- 15 mins In Milli Seconds.Ensure Repeat Interval and Refresh Interval should be same-->
    <ref bean="repeatInterval" />
    </entry>
    <entry key="environment">
    <ref bean="Environment" />
    </entry>
    </map>
    </property>
    </bean>
    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <property name="jobDetail">
    <!-- see the example of method invoking job above -->
    <ref bean="notificationSchedulerBean" />
    </property>
    <property name="startDelay">
    <!--15 mins (In milli seconds )-->
    <value>900000</value>
    </property>
    <property name="repeatInterval">
    <!--15 mins (In milli seconds )-->
    <ref bean="repeatInterval" />
    </property>
    </bean>
    <bean id="repeatInterval" class="java.lang.Long">
    <constructor-arg>
    <value>900000</value>
    </constructor-arg>
    </bean>
    <bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="triggers">
    <list>
    <ref bean="simpleTrigger" />
    </list>
    </property>
    </bean>

    <!-- SCHEDULER CONFIG END -->
    <!-- HibernateTemplate configuration -->
    <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.Hibernat eTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <!-- DAO config -->
    <bean id="ApplicationSettingDAO"
    class="core.domain.ApplicationSettingDAO"
    abstract="false" singleton="true" lazy-init="default"
    autowire="default" dependency-check="default">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate" />
    </property>
    </bean>
    <!-- OpenSessionViewFilter in Web.xml Setup -->
    <servlet>
    <servlet-name>SpringContext</servlet-name>
    <servlet-class>
    org.springframework.web.context.ContextLoaderServl et
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <filter>
    <description>
    This filter overwrites OpenSessionInViewFilter to make flush
    mode to COMMIT.
    </description>
    <filter-name>applicationSessionFilter</filter-name>
    <filter-class>
    core.view.filter.ApplicationSessionFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>applicationSessionFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>applicationSessionFilter</filter-name>
    <url-pattern>*.xhtml</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>applicationSessionFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    </filter>

    When we deploy the application to tomcat or weblogic 9.2
    Scenario1
    If i don't open the application URL say for 15 mins (Which is the start delay for scheduler)
    The scheduler kicksoff and the scheduler works fine.
    As soon as i hit a Url of the application, from then on scheduler throws exception saying unable to open connection as the connection is already closed.
    Scenario2
    When i open the application just after the deployment, then the scheduler starts after 15 mins, it doesn't complain about the connection or the hibernate session.


    public class ApplicationSessionFilter extends OpenSessionInViewFilter {

    public ApplicationSessionFilter() {
    super();
    Logger.log(this, "OpenSessionInViewFilter... Initialised...");
    }
    protected Session getSession(SessionFactory sessionFactory)
    throws DataAccessResourceFailureException {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(FlushMode.AUTO);
    Logger.log(this, "ApplicationSessionFilter.getSession() invoked...");
    return session;
    }

    /**
    * we do an explicit flush here just in case we do not have an automated
    * flush
    */
    protected void closeSession(Session session, SessionFactory factory) {
    session.flush();
    super.closeSession(session, factory);
    Logger.log(this, "ApplicationSessionFilter.closeSession() invoked...");

    }
    }

    Am i missing something here.

  • #2
    Its more than 10 days, no answer yet..
    Can anyone help me in solving this....

    Comment


    • #3
      Consider using HibernateInterceptor instead

      Im not even going to read your post, you should use the code tags so that it is readable. This works for me:

      Code:
        <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
           <property name="sessionFactory">
             <ref bean="sessionFactory"/>
           </property>
        </bean>
      
       <bean id="backgroundJobTemplate"
          abstract="true"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionAttributes">
            <props>
              <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
          </property>
          <property name="transactionManager" ref="transactionManager"/>
          <property name="preInterceptors" ref="hibernateInterceptor"/>
        </bean>
      
        <bean id="backgroundJob" parent="backgroundJobTemplate">
          <property name="target">
            <bean class="com.foo.Bar"/>
          </property>
        </bean>
      
        <bean id="backgroundJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
          <property name="targetObject" ref="backgroundJob"/>
          <property name="targetMethod" value="run"/>
        </bean>
      That way your not tied into your hibernate session being bound to the life of the request object (which is why your session is being closed when the response has been rendered upon hitting the URL), rather to the life of the job itself.

      HTH,

      Aaron.

      Comment

      Working...
      X