开发者社区 问答 正文

Quartz Job的事务

编写的作业需要持久化到数据库,可是怎么控制一个job内的事务

例如

public class UpdateUserJob extends QuartzJobBean {

 .....

     protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {

           service.a();

         service.b(); 

  }

}

怎么控制整个 Job 的事务?

展开
收起
a123456678 2016-03-12 17:50:29 4218 分享 版权
1 条回答
写回答
取消 提交回答
  • 如果用spring,可以用编程式控制事务

    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus ts) {
                try {
                    //做你的事
                } catch (Exception e) {                 
                    ts.setRollbackOnly();                       
                }
                return null;
        }
    });
    2019-07-17 19:01:18
    赞同 展开评论
问答分类:
问答地址: