【问题标题】:How to add synchronization to Atomikos TransactionStateHandler如何向 Atomikos TransactionStateHandler 添加同步
【发布时间】:2018-11-12 14:24:22
【问题描述】:

如何在 atomikos 中向 TransactionStateHandler 添加同步?默认只包含 JdbcRequeueSynchronization ,其中 beforeCompletion 方法为空

private Throwable notifyBeforeCompletion() {
    Throwable cause = null;
    Synchronization sync = localPopSynchronization();
    while ( sync != null ) {
        try {
            sync.beforeCompletion ();
        } catch ( RuntimeException error ) {
            // see case 24246: rollback only
            setRollbackOnly();
            // see case 115604
            // transport the first exception here as return value
            if (cause == null) {
                cause = error;
            } else {
                // log the others which may still happen as error - cf. case 115604
                LOGGER.logError("Unexpected error in beforeCompletion: ", error);
            }               
        }
        sync = localPopSynchronization();
    }
    return cause;
}

【问题讨论】:

    标签: atomikos


    【解决方案1】:

    您可以通过 Transaction 对象(在 JTA API 中)执行此操作:

    UserTransactionManager utm = new UserTransactionManager();
    utm.begin(); //optional, skip if you already have a transaction
    Transaction tx = utm.getTransaction();
    tx.registerSynchronization(...);
    ...
    //commit / rollback per your requirements
    

    希望有帮助

    男人

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      相关资源
      最近更新 更多