WebSphere Application Server for i5/OS, Version 6.1   
             オペレーティング・システム: i5/OS

             目次と検索結果のパーソナライズ化

例: タイマー・サービスの使用

この例は、スケジュール済みのイベントが起こるときに呼び出される ejbTimeout() メソッドのインプリメンテーションを 示しています。

ejbTimeout メソッドには、通常は Bean のビジネス・メソッドに置かれ るコードを含めることができます。 transaction または runAs などのメソッド・レベル属性は 、アプリケーション・アセンブラーによってこのメソッドと関連付けることができます。 メソッドを発行するタイマー・オブジェクトのインスタンスは、ejbTimeout() に引数として渡されます。

import javax.ejb.Timer;
import javax.ejb.TimedObject;
import javax.ejb.TimerService;

public class MyBean implements EntityBean, TimedObject {

  // This method is called by the EJB container upon Timer expiration.
  public void ejbTimeout(Timer theTimer) {

    // Any code typically placed in an EJB method can be placed here.

     String whyWasICalled = (String) theTimer.getInfo():
     System.out.println("I was called because of"+ whyWasICalled);
  } // end of method ejbTimeout

このセクションでは、ejbTimeout() メソッドを 30 秒で開始するタイマーが作成されます。 単一のストリング・オブジェクトは、タイマー作成で渡され、タイマーを識別します。

// Instance variable to hold the EJB context.
private EntityContext theEJBContext;

// This method is called by the EJB container upon bean creation.
public void setEntityContext(EntityContext theContext) {

// Save the entity context passed in upon bean creation.
  theEJBContext = theContext;

}

// This business method causes the ejbTimeout method to begin in 30 seconds.
public void fireInThirtySeconds() throws EJBException  {

  TimerService theTimerService = theEJBContext.getTimerService();
  String aLabel = "30SecondTimeout";
  Timer theTimer = theTimerService.createTimer(30000, aLabel);

} // end of method fireInThirtySeconds

} // end of class MyBean



関連タスク
Network Deployment のタイマー・サービスの構成
関連情報
EJB タイマー・サービス設定
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 5:46:14 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.base.iseries.doc/info/iseries/ae/rejb_timerex.html