Question

I have a long running process which runs inside a Seam component that takes about 60sec to complete, to allow its progress to be displayed I write to the database during its execution.

When the process is invoked from a JAXRS bean (via Restful API) the process works fine and the database is getting updated mid-method

But when the processing is invoked from a Quartz scheduled job (using a @MessageDriven) the updates only appear in the database once the method completes

Is this because of a difference in persistence between EJB/Seam components? Is there any way to force the changes to the database?

I am using a SMPC

The scheduled task looks like this...

@Name("minuteActions")
@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "11 * * * * ?")
})
@ResourceAdapter("quartz-ra.rar")
@Depends({"jboss.web.deployment:war=processor/"})
public class MinuteActions implements Job{

    @Logger private Log log;
    @In private ProcessSession processSession;

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException{

        processSession.processNewSession();

    }


}

And this is the processing (Seam) bean

@AutoCreate
@Name("processSession")
public class ProcessSession{

    @Logger private Log log;
    @In private SessionDAO sessionDAO;

    public ProcessingRun processNewSession(Session session){

            session.setProcessingStartTime(new Date());
        sessionDAO.persist(session);

            //Some long running processing ~60sec

            session.setProcessingEndTime(new Date());
            sessionDAO.persist(session);

    }

}
Was it helpful?

Solution

In the end I have achieved this using Bean Managed Transactions that allow you to determine the transaction boundaries manually...

@TransactionManagement(value=TransactionManagementType.BEAN)
@AutoCreate
@Name("processSession")
public class ProcessSession{

    @Resource private UserTransaction userTransaction;
    @Logger private Log log;
    @In private SessionDAO sessionDAO;

    public ProcessingRun processNewSession(Session session){

            userTransaction.begin();
            session.setProcessingStartTime(new Date());
            sessionDAO.persist(session);

            userTransaction.commit();
            userTransaction.begin();

            //Some long running processing ~60sec

            session.setProcessingEndTime(new Date());
            sessionDAO.persist(session);

            userTransaction.commit();

    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top