TaskNameAccessor API를 사용하여 TaskName 설정
런타임 시 JPA(Java™ Persistence API) TaskName을 설정하기 위해 TaskNameAccessor API 사용하십시오.
이 태스크 정보
EJB(Enterprise JavaBeans) 컨테이너에서 태스크 이름은 기본적으로 트랜잭션이 시작할 때 자동으로 설정됩니다. 이 조치는 컴포넌트나 비즈니스 메소드가 CMT 세션 Bean에서 호출될 때 또는 애플리케이션이 BMT 세션 Bean에서 sessionContext.getTransaction().begin()을 호출할 때 수행됩니다. 이 TaskName은 완전히 패키지 규정 세션 Bean 유형, 도트 문자 및 메소드 이름의 연결로 구성됩니다. 예: com.acme.MyCmtSessionBean.methodABC.
웹 컨테이너의 컨텍스트에서 JPA를 사용하는 경우 애플리케이션은 TaskNameAccessor API를 사용하여 실행의 현재 스레드에서 TaskName을 설정해야 합니다.

다음 예에
TaskNameAccessor API 정의가 들어 있습니다.
package com.ibm.websphere.persistence;
public abstract class TaskNameAccessor {
/**
* Returns the current task name attached in the current thread context.
* @return current task name or null if none is found.
*/
public static String getTaskName ();
/**
* Add a user-defined JPA access intent task name to the current thread
* context.
*
* @param taskName
* @return false if an existing task has already attached in the current
* thread or Transaction Synchronization Registry (TSR) is not
* available (i.e. in JSE environment).
*/
public static boolean setTaskName(String taskName);
}
다음 코드 예는 TaskNameAccessor를 사용하여
TaskName을 설정하는 방법을 보여줍니다.
package my.company;
@Remote
class Ejb1 {
// assumer no tx from the caller
@TransactionAttribute(Requires)
public void caller_Method1() {
// an implicit new transaction begins
// TaskName "my.company.Ejb1.caller_Method1" set on TSR
ejb1.callee_Method?();
}
@TransactionAttribute(RequiredNew)
public void callee_Method2() {
// an implicit new transaction begins i.e. TxRequiredNew.
// TaskName "my.company.Ejb1.callee_Method2" set on TSR
}
@TransactionAttribute(Requires)
public void callee_Method3() {
// In caller's transaction, hence TaskName remains
// "my.company.Ejb1.caller_Method1"
}
@TransactionAttribute(NotSupported)
public void callee_LocalTx () {
// Unspecified transaction, a new local transaction implicitly started.
// TaskName "my.company.Ejb1.callee_LocalTx" set on TSR
}
}
주의: 이 예에서, 애플리케이션은 Ejb1이 로컬 인터페이스(@Local)를 사용하는 경우
트랜잭션 경계가 미묘하게 변할 것임을 인식해야 합니다. 예를 들어, caller_Method1()가 callee_Method3 또는 callee_LocalTx를
호출하는 경우, 이것은 Java 메소드 호출로
취급됩니다. EJB 트랜잭션 시맨틱을 따르지 않습니다.