user725455
user725455

Reputation: 475

JBOSS EAP 6 blocked to call ejb method after asynchronous method

I have a stateless bean that insert some data using asynchronous method of other bean ( local injection). This data insertion takes a time , so I do not wait to finish for this operation. After this data insertion, I am calling another method of same bean. When I put a debug point to method, server waits for approximately 90 seconds to reach this point. May be Jboss waits for transaction to complete for asynchronous method. I do not know what is going on. .

   @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) {

} 

This is other bean called from main bean

 @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);
        }
    }

This is client calls main bean.This works asynchronously.

    getSimulationEJB().persistSimulationResults(id, tsaParser.getLstFile().getGraphArray());

After calling this method, I call another method of SimulationNodePersistenceBean.This method waits for some minutes.

getSimulationEJB().calculateSimIndex(contSimId);

I have created a thread dump using jstack. Actually I do not have this problem in Jboss As 6. I migrated my application to Jboss EAP 6. 4. May be I need to make some configuration changes in configuration. But I do not know what should I do.

I checked thread dump. I did not find any thread in BLOCKING state. Should I look for other keywords?

Upvotes: 0

Views: 826

Answers (1)

Aditya K
Aditya K

Reputation: 487

As I already pointed out in the comments, you are mixing the calling of Asynchronous and Synchronous methods. In your example, you are calling the addResultGraphsToDatabase method (Which is a Asynch method) from persistSimulationResults method (which is a synch method - since you have commented out the asynchronous annotation on top of it). Therefore, right now the addResultGraphsToDatabase method is behaving like a Synchronous method despite the Asynchronous annotation.

I am not sure if you took a look at the link that I posted in the comments but you need to call the Asynch method using the SessionContext. Something like this:

At the class level:

@Inject
SessionContext ctx;

The, within the persistSimulationResults method:

ctx.addResultGraphsToDatabase

For a more detailed example, please take a look at the link I have posted in the comments.

Upvotes: 2

Related Questions