有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Quatz作业在spring中未使用Quartz进行triigered

下面是我与Spring的quatz集成,但它不起作用,即未触发作业。我可以看到quartz在几毫秒内检查了MySQL数据库,这意味着与MySQL的连接很好,并且记录被插入到表中,但下面的类中提到的Sysout并没有出现在控制台中。请告知可能的根本原因-

来自Spring配置XML

<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="corePoolSize" value="5" />
        <property name="maxPoolSize" value="50" />
        <property name="WaitForTasksToCompleteOnShutdown" value="true" />
    </bean>

    <bean id="exampleBusinessObjectJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <bean name="exampleBusinessObjectJob" class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="name" value="exampleBusinessObjectJob"/>
                <property name="jobClass" value="com.aexp.mars.job.ExampleJob"/>
            </bean>
        </property>
        <property name="cronExpression" value="0 */1 * * * ?"/>
    </bean>

    <bean id="exampleBusinessObjectJob" class="com.aexp.mars.job.ExampleJob">
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

        <property name="applicationContextSchedulerContextKey" value="applicationContext"/>

        <property name="autoStartup" value="true"/>

        <property name="triggers">
            <list>
                <ref bean="exampleBusinessObjectJobTrigger" />
            </list>        
        </property>
        <property name="quartzProperties">
            <props>
                <prop key="org.quartz.scheduler.instanceName">MARS_SCHEDULER</prop>
                <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                <prop key="org.quartz.scheduler.instanceId">10000</prop>
                <prop key="org.quartz.scheduler.instanceId">600000</prop>
                <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                <prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
                <prop key="org.quartz.threadPool.threadCount">3</prop>
                <prop key="org.quartz.threadPool.threadPriority">5</prop>
                <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
                <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
                <prop key="org.quartz.jobStore.useProperties">false</prop>
                <prop key="org.quartz.jobStore.dataSource">marsDS</prop>
                <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
                <prop key="org.quartz.jobStore.isClustered">true</prop>
                <prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
                <prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">20</prop>
                <prop key="org.quartz.dataSource.marsDS.driver">com.mysql.jdbc.Driver</prop>
                <prop key="org.quartz.dataSource.marsDS.URL">{server_url}</prop>
                <prop key="org.quartz.dataSource.marsDS.user">{user_name}</prop>
                <prop key="org.quartz.dataSource.marsDS.password">{password}</prop>
                <prop key="org.quartz.dataSource.marsDS.maxConnections">10</prop>
                <prop key="org.quartz.dataSource.marsDS.validationQuery">select 1</prop>
                <prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                <prop key="org.quartz.plugin.shutdownHook.cleanShutdown">false</prop>
            </props>
        </property>
        <property name="taskExecutor" ref="myTaskExecutor" />
        <property name="jobFactory">
            <bean class="com.aexp.mars.job.MarsSpringBeanJobFactory"/>
        </property>
    </bean>

**Java类-**

public class ExampleJob   {

    private static final Logger LOG = LoggerFactory.getLogger(ExampleJob.class);


    protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
          System.out.println("Job is running");
          LOG.info("Job ran");
    }

    public void execute(JobExecutionContext ctx) throws JobExecutionException {
          System.out.println("Job#1 is running");
          LOG.info("Job ran");
    }

}

共 (1) 个答案

  1. # 1 楼答案

    明白了。我更改了cron expression的值,使其每1分钟运行一次,但它仍然设置为我以前的值(即凌晨3点)。我在下面添加了属性,然后新的cron表达式开始工作

    <property name="overwriteExistingJobs" value="true"/>