2012-12-01 61 views
1

我必須在ejb中使用@schedule註釋每10分鐘一個接一個地運行兩個方法。如何運行兩個用@Schedule一個接一個註釋的方法ejb

我的代碼是這樣的:

@Schedule(minute="*/10") 
public void mth1() { 
    System.out.println("welcome"); 
} 

@Schedule(minute="*/10")  
public void mth2() { 
    System.out.println("hello"); 
} 

如何進行?

感謝您的答覆..但是,計時器分別設置爲10分鐘mthds.2nd mthd開始執行後第1個月完成。如果我在第一個mthd中調用第二個mthd,兩個都在10分鐘內運行..我想每個運行10分鐘

回答

3

如果你想在mth1之後執行mth2,你可以在mth1的末尾調用mth2並刪除第mth2個日程安排註釋。

0

您可以嘗試下面的代碼讓計時器依次執行,延遲特定的時間間隔。

@Schedule(minute="*/10") 
public void mth1() { 
    System.out.println("welcome"); 

    //-- Creating a timer manually for mth2 
    timerService.createTimer(duration, info); 

} 

在指定的時間間隔後,將調用超時方法,用@Timeout註釋標記meth2()。因此,當meth1()退出時,將在x單位持續時間後調用meth2()。

@Timeout 
public void mth2(Timer timer){ 
    System.out.println("hello"); 
} 
相關問題