2013-08-19 53 views
2

我在JBoss的計劃任務:如何安排JBoss任務?

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

如何寫這個任務,將在1:00 AM在每月的第一天執行? 謝謝!

回答

0

您需要創建一個調度類。 org.jboss.varia.scheduler.Scheduler

由於您想每月執行一次,因此無法將其指定爲屬性。你將需要另一個類來處理設置下一個時間間隔。 Java Monthly Timer

調度程序類調用每月定時器來獲取下一個時間間隔並進行設置。也許在初始階段傳遞一些值。

<mbean code="org.jboss.varia.scheduler.Scheduler" 
     name="jboss.docs:service=Scheduler"> 
    <attribute name="StartAtStartup">true</attribute> 
    <attribute name="SchedulableClass">org.jboss.book.misc.ex2.ExSchedulable</attribute> 
    <attribute name="SchedulableArguments">01:00</attribute> <!-- 24hr time hh:mm --> 
    <attribute name="SchedulableArgumentTypes">java.lang.String</attribute> 

</mbean> 

ExSchedulable(這只是僞代碼)

public ExSchedulable(String time) { 
    Date tDate = new Date(); 
    tDate.setTime(time); 

    Monthly monthyObj = Monthly(1); //Day of the month 
    //Gets the next interval date specified from the day of the month 
    Date nextInterval = monthyObj .getNextInterval(tDate); 

}