在无状态对象中可能有两种事务类型= required_new吗?

时间:2015-08-23 18:05:23

标签: java transactions ejb jta

请参阅下面的伪代码。

        PFPush *push = [[PFPush alloc] init];

        NSString *to = [[[AppDelegate appDelegate].sendTo componentsSeparatedByString:@"@"] firstObject];

        [push setChannel:[NSString stringWithFormat:@"z%@",to]];

        [push setMessage:@"dscxvx"];

        [push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError * __nullable error) {

            if (succeeded) {

                NSLog(@"succeeded");

            }

            NSLog(@"error==%@",error.localizedDescription);

        }];

这是Java EJB应用程序的一小部分。该应用程序正在使用JTA事务。

我想知道可能将方法A和B声明为transaction_type = requires_new。

坦率地说,我几乎看不到任何在线教程在无状态对象中允许两个requires_new事务类型。我最看到的是方法A声明为必需,方法B声明为requires_new。

谢谢。

1 个答案:

答案 0 :(得分:0)

如果在methodA和methodB上使用Requires_New,则说明了Transaction的目的。因为基本上你是为这两种方法创建一个新的事务。这与孤立地运行它们一样好 如果您只想从事务中排除方法,请使用NotSupported属性。

您已经看到了具有RequiresNew和Required属性的方法,因为在事务中,事务是在第一次使用Requires_New进行方法调用时启动的,然后该事务由另一个使用Required的方法使用。