EJB / MDB无法在中间方法中保留数据

时间:2014-04-24 21:34:01

标签: ejb quartz-scheduler seam seam2

我有一个长时间运行的进程,它在Seam组件内部运行,需要大约60秒才能完成,以便在执行期间写入数据库以显示其进度。

当从JAXRS bean(通过Restful API)调用进程时,该过程正常工作并且数据库在方法中更新

但是当从Quartz预定作业(使用@MessageDriven)调用处理时,只有在方法完成后,更新才会出现在数据库中

这是因为EJB / Seam组件之间的持久性存在差异吗?有没有办法强制更改数据库?

我正在使用SMPC

计划任务看起来像这样......

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

    }


}

这是处理(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);

    }

}

1 个答案:

答案 0 :(得分:0)

最后,我使用Bean管理事务实现了这一点,允许您手动确定事务边界...

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

    }

}