0
votes

at first my application save the cron details from the browser into the databse later the scheduling should take palce by getting the details. how can we set the cron expression dynamically in the applicationcontext. When i start the application the scheduler start and run the job actually i dont want that to happen. i want the job to run after user getting the values from the browser an base up on the database values it should trigger

applicationcontext.xml

<bean id="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.JobCSVfile" />
        <property name="jobDataAsMap">
            <map>
                <entry key="timeout" value="5" />
            </map>
        </property>
    </bean>
    <bean id="cronTriggerJobA" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="JobA" />
        <property name="cronExpression" value="0/5 * * * * ?" />
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails"> <list> <ref bean="JobA" /> </list> </property>

        <property   <list>
                <ref bean="cronTriggerJobA" />

            </list>
        </property>
    </bean>
1

1 Answers

1
votes

You can set the property "autoStart" of CronSchedulerBean to false, this would mean that Cron job will be not executed after application starts. Once you are ready with proper parameters, you can enable cron job.

See this api: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/scheduling/quartz/SchedulerFactoryBean.html#setAutoStartup(boolean)