简体   繁体   English

Quartz Scheduler时间设置-不接受逗号

[英]Quartz scheduler time setting - comma not accepted

I'm trying to set a Quartz job to run every minute in every hour, except in 0 and 30 minutes. 我正在尝试将Quartz作业设置为每小时每小时运行一次,除了0和30分钟。

When I try to configure like this: 当我尝试像这样配置时:

ScheduledSenderJob=0 2-28 * * * ?

It works perfectly for me. 它非常适合我。 But when I try this: 但是当我尝试这个:

ScheduledSenderJob=0 2-28,35-58 * * * ?

I got an Exception, when I launch Glassfish server: CronException, invalid character, . 启动Glassfish服务器时出现异常:CronException,无效字符,。 Somehow the comma character doesn't seem to work, and I couldn't work it out. 逗号字符似乎不起作用,我也无法解决。

Could someone help me out, what the correct scheduling would be? 有人可以帮助我,正确的安排是什么? Thank you. 谢谢。

Stacktrace: 堆栈跟踪:

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: CronExpression '0 2-28' is invalid,.
at eu.pont.zf.szkif.sched.quartz.QuartzServicesImpl.startScheduling(QuartzServicesImpl.java:200)
at eu.pont.zf.szkif.sched.quartz.QuartzServicesImpl.init(QuartzServicesImpl.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:206)
... 48 more

UPDATED: 更新:

Whatever software is providing you access to the ScheduledSenderJob property is interpreting the string and tokenizing on the commas. 无论使用哪种软件提供访问ScheduledSenderJob属性的权限,都将解释字符串并在逗号上标记化。 Below is an example app that loads your cron expression from a java properties file and runs without a problem: 以下是一个示例应用程序,可从java属性文件加载cron表达式并运行无问题:

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;

    import org.quartz.SchedulerFactory;
    import org.quartz.Trigger;


    /**
     * Hello world!
     *
     */
    public class App 
    {

        public static void main( String[] args )
        {
             SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

              Scheduler sched;
            try {
                sched = schedFact.getScheduler();

                Properties props = new Properties();
                InputStream inputStream = sched.getClass().getClassLoader()
                        .getResourceAsStream("test.properties");

                props.load(inputStream);

                String cronString = props.getProperty("cron");

                  // define the job and tie it to our HelloJob class
                  JobDetail job = JobBuilder.newJob(HelloJob.class)
                      .withIdentity("myJob", "group1")
                      .build();

                System.out.println( "Hello World!" );
                Trigger trigger = newTrigger()
                        .withIdentity("trigger3", "group1")
                        .withSchedule(cronSchedule(cronString))
                        .forJob("myJob", "group1")
                        .build();

                sched.scheduleJob(job,trigger);
                sched.start();
            } catch (SchedulerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

    }

HelloJob.java: HelloJob.java:

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class HelloJob implements Job{

    public void execute(JobExecutionContext arg0) throws JobExecutionException {
        System.out.println("Hello ! ");

    }

}

test.properties - I moved the timing bits to seconds to see the results faster. test.properties-我将计时位移动到秒以更快地查看结果。

cron=2-28,35-58 * * * * ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM