예: TimedObject 인터페이스에서 타이머 서비스 사용

이 예는 예정된 이벤트 발생 시 호출되는 ejbTimeout() 메소드의 구현을 보여줍니다.

우수 사례 우수 사례: EJB 3.x 프로그래밍 모델은 비즈니스 환경 안에서 지속적 및 비지속적 타이머를 정의하기 위한 추가 전략적 방법을 제공합니다. TimedObject 인터페이스와 함께 ejbTimeout 메소드를 사용한 지속적 타이머 정의가 아직 지원되지만, 구현하기 쉬운 EJB 어노테이션을 활용하여 사용자의 비즈니스 수요에 맞추기 위한 지속적 및 비지속적 타이머를 작성하십시오. 어노테이션을 사용한 지속적 및 비지속적 타이머 작성 또는 배치 디스크립터 내에서 사용자 자신의 timeout 메소드 정의에 대해 더 자세히 알려면 엔터프라이즈 Bean 정보에 대한 EJB 타이머 서비스 사용을 참조하십시오. bprac

ejbTimeout 메소드는 일반적으로 Bean의 비즈니스 메소드에 위치하는 모든 코드를 포함할 수 있습니다. 트랜잭션 또는 runAs 같은 메소드 레벨 속성은 애플리케이션 어셈블러에 의해 이 메소드와 연관될 수 있습니다. 메소드가 실행하게 만드는 Timer 오브젝트의 인스턴스가 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

30초 안에 ejbTimeout 메소드를 시작하는 타이머가 작성됩니다. 타이머 작성 시 타이머를 식별하기 위한 간단한 문자열 오브젝트가 전달됩니다.

  // 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;
  } // end of method setEntityContext

  // 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

주제 유형을 표시하는 아이콘 참조 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rejb_timerex_v8
파일 이름:rejb_timerex_v8.html