2016-10-18 2 views
0

다른 bean (로컬 삽입)의 비동기 메소드를 사용하여 일부 데이터를 삽입하는 상태 비 저장 빈을 보유하고 있습니다. 이 데이터 삽입에는 시간이 걸리기 때문에이 작업을 마칠 때까지 기다리지 않아도됩니다. 이 데이터 삽입 후 같은 bean의 다른 메소드를 호출하려고한다. 디버그 지점을 메서드에 넣으면 서버는이 지점에 도달하는 데 약 90 초 동안 기다립니다. Jboss는 트랜잭션이 비동기 메소드를 완료하기를 기다릴 수 있습니다. 나는 무슨 일이 일어나고 있는지 모른다. .JBOSS EAP 6은 비동기 방식으로 ejb 메소드 호출을 차단했습니다.

@Stateless 
public class SimulationNodePersistenceBean implements SimulationNodePersistenceRemote, SimulationNodePersistenceLocal { 
    @Resource 
    SessionContext context; 

    @EJB 
    private SimulationResultGraphPersitenceBean graphPersistenceBean; 

    @Asynchronous 
    @TransactionAttribute(TransactionAttributeType.REQUIRED) 
    private void addResultGraphsToDatabase(long id, Graph[] graphList) { 

    ResultGraph paramGraph; 
    ResultGraphPoint dataPoint; 
    Graph graph; 
    for (int i = 0; i < graphList.length; i++) { 
     graph = graphList[i]; 
     paramGraph = new ResultGraph(); 

     try { 
      graphPersistenceBean.persistGraph(paramGraph); 
     } catch (Exception databaseException) { 
      // TODO add error message to the contingency simulation messages 
      // list 
      logger.error("Error saving ResultGraph:" + paramGraph); 
     } 
    } 
    long duration = System.nanoTime() - startTime; 
    logger.debug("Graphs inserted to DB in (sec) :" + (duration/NANO_SECOND_CONVERSION_FACTOR)); 
} 

    // @Asynchronous 
public void persistSimulationResults(long contingencySimulationId, Graph[] graphList, 
     List<AB> reiList) { 
    if (graphList != null) { 
     addResultGraphsToDatabase(contingencySimulationId, graphList); 
    } 
    if (reiList != null) { 
    //another method 
    } 
    calculateContSimStability(contingencySimulationId); 
} 

    @Override 
public void calculateSimIndex(long id) { 

} 

주요 콩

@Stateless 
public class SimulationResultGraphPersitenceBean { 
    @PersistenceContext(unitName = "DBService") 
    private EntityManager em; 

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 
    @Asynchronous 
    public void persistGraph(ResultGraph graph) throws SiGuardPersistenceException { 
     try { 
      ResultGraphService service = new ResultGraphService(em); 
      service.create(graph); 
      em.flush(); 
     } catch (Exception ex) { 
      throw new PersistenceException("Error persisting graph", ex); 
     } 
    } 

에서 호출 이것은 다른 콩이 클라이언트입니다 주요 bean.This는 비동기 적으로 작동 호출합니다.

이 메서드를 호출 한 후에는 SimulationNodePersistenceBean의 다른 메서드를 호출합니다.이 메서드는 몇 분 동안 기다립니다.

getSimulationEJB().calculateSimIndex(contSimId); 

jstack을 사용하여 스레드 덤프를 만들었습니다. 실제로 Jboss As 6에서이 문제가 발생하지 않았습니다. Jboss EAP 6으로 응용 프로그램을 마이그레이션했습니다. 4. 구성을 변경해야 할 수도 있습니다. 그러나 나는 무엇을해야하는지 모른다.

스레드 덤프를 확인했습니다. 블로킹 상태에서는 스레드를 찾지 못했습니다. 다른 키워드를 찾아야합니까?

+0

문제를 설명하기 위해 몇 가지 샘플 코드 (또는 의사 코드)를 제공 할 수 있다면 쉽게 이해할 수 있습니다. –

+0

코드를 추가하여 편집했습니다. – user725455

+0

addResultGraphsToDatabase() 메소드에 대한 호출이 표시되지 않습니다. 내 생각 엔 당신이 persistSimulationResults()에서 호출하는 것입니다. 무엇보다도 비동기 적으로 호출되었는지 확인해야합니다 (비동기 및 동기화 메소드를 혼합 할 때). 비동기 메소드를 sessionContext에서 호출하는 것을 잊지 마십시오. 나는 당신이이 일반적인 실수를 저 지르지 않았 음을 확신하고 싶습니다. https://satishgopal.wordpress.com/2011/04/24/ejb-3-1-asynchronous-methods/ ("동기화 및 비동기 혼합"단락을보십시오) 여기를보십시오. 알려줘. –

답변

1

주석에서 이미 지적했듯이 비동기 및 동기 메서드 호출을 혼합합니다. 귀하의 예제에서는 persistSimulationResults 메소드 (비동기 주석을 주석 처리 했으므로 synch 메소드)에서 addResultGraphsToDatabase 메소드 (Asynch 메소드)를 호출하고 있습니다. 따라서 현재 addResultGraphsToDatabase 메서드는 비동기 주석이 있더라도 동기 메서드처럼 작동합니다.

내가 주석에 게시 한 링크를 살펴 봤지만 SessionContext를 사용하여 Asynch 메서드를 호출해야하는지 잘 모르겠습니다. 이런 식으로 뭔가 :

클래스 수준에서 :

@Inject 
SessionContext ctx; 

는 persistSimulationResults 방법 내 : 더 자세한 예를 들어

ctx.addResultGraphsToDatabase 

, 내가 게시 한 링크에서 봐 주시기 바랍니다 의견에.

+0

답장을 보내 주셔서 감사합니다. persistSimulationResult 메서드를 비동기 메서드로 정의해야합니까?내부에서 호출 된 다른 메소드가 비동기 적으로 작동해서는 안되기 때문에 – user725455

+0

\t \t \t context.getBusinessObject (SimulationNodePersistenceBean.class) .addResultGraphsToDatabase (contingencySimulationId, graphList);를 사용하여 addResultGraphsToDatabase 메소드를 호출하려고했습니다. 그것은 불법 스테이트 예외를 던졌습니다. – user725455

+0

나를 도와 줄 수있는 스택 트레이스의 처음 몇 줄을 게시하십시오. –

관련 문제