0

我在 JBoss 中安排了任务:

<?xml version="1.0" encoding="UTF-8"?>
 <server>
  <mbean code="org.jboss.varia.scheduler.Scheduler" name="acme:service=Scheduler">
   <attribute name="…">…&lt;/attribute>
…
  </mbean>
 </server>

如何编写这个任务,它将在每个月的第一天凌晨 1:00 执行?谢谢你!

4

2 回答 2

0

使用EJB 调度器怎么样?

否则,请在此处检查:

<mbean code="org.jboss.varia.scheduler.Scheduler" name="jboss.test:service=MyScheduler">
    <attribute name="StartAtStartup">true</attribute>
    <attribute name="SchedulableClass">test.MySchedulable</attribute>
    <attribute name="SchedulableArguments">MySchedulable,100</attribute>
    <attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute>
    <attribute name="InitialStartDate">NOW</attribute>
    <attribute name="SchedulePeriod">5000</attribute>
    <attribute name="InitialRepetitions">10</attribute>
</mbean>

可调度:

package test;
import java.util.Date;
import org.jboss.varia.scheduler.Schedulable;
import org.apache.log4j.Logger;
public class MySchedulable implements Schedulable
{
    private static final Logger log = Logger.getLogger(MySchedulable.class);

    private String name;
    private long value;

    public MySchedulable(String name, long value)
    {
        this.name = name;
        this.value = value;
        log.info("nt name: " + name + ", value: " + value);
    }

    public void perform(Date now, long repetitions)
    {
        log.info("perform(), time: " + now +", repetitions: " + repetitions +", name: " + name + ", value: " + value);
    }
}
于 2013-07-05T09:41:38.913 回答
0

这个怎么样

在 jboss-service.xml 中

<!-- Put a real date here -->
<attribute name="InitialStartDate">01-01-01 01:00</attribute>
<attribute name="SchedulePeriod">86400000</attribute>

然后在Java中

package com.example.scheduler.job;

import java.util.Date;
import org.jboss.varia.scheduler.Schedulable;
import org.apache.log4j.Logger;

public class MyJobScheduler implements Schedulable {

    public MyJobScheduler() {}

    public void perform(Date now, long repetitions) {

         Calendar calendar = Calendar.getInstance();
         calendar.setTime(now);
         int day = calendar.get(Calendar.DAY_OF_MONTH);            
         if(day == 1) {
            // Do stuff
         }
    }
}

我知道这个问题很老了,但你怎么看?

于 2014-03-26T16:32:41.997 回答