0

我需要创建一个带有 job1 条件的调度器

1)当job1中的某些条件失败时,我需要让工作休眠一段时间?

查询

1)我如何在 jsf 中使用石英 2.1.x 或更高版本执行此操作

  public class SchedulerJob implements Job {

 int  i= 1 ;
@Override
public void execute(JobExecutionContext context)
        throws JobExecutionException {

       DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
       Date date = new Date();
   System.out.println("scheduler wotking with JSF and Hibernate "+ dateFormat.format(date));


        i=i+1;
        System.out.println(i);
           if (i==2)
           {
                System.out.println(i);
       try {

           // 15*60 =900 sec = 15 min

                Thread.sleep( 900L * 1000L); 
                 System.out.println("After 65 sec");
                  System.out.println("");
                // executing...
            } catch (Exception e) {
                e.printStackTrace();
            }


}
    }

  }

石英调度器是这个

<schedule>
    <job>
        <name>AJob</name>
        <group>AGroup</group>
        <description>Print a welcome message</description>
        <job-class>com.mdis.scheduler.SchedulerJob</job-class>
    </job>

    <trigger>
        <cron>
            <name>dummyTriggerName</name>
            <job-name>AJob</job-name>
            <job-group>AGroup</job-group>
            <!-- It will run every 5 seconds -->
            <cron-expression>0/5 * * * * ?</cron-expression>
        </cron>
    </trigger>
</schedule>

这种睡眠正在起作用……但这是正确的方法吗?

  Thread.sleep( 900L * 1000L); 
4

0 回答 0