简体   繁体   English

检测事务是否失败并通过objectify重新运行

[英]detect if transaction fails and is rerun with objectify

I am using objectify as an interface to the GAE datastore and am wondering how I can detect when a transaction fails. 我将objectify用作GAE数据存储的接口,并且想知道如何检测事务何时失败。 That is, when you call 也就是说,当您打电话时

ofy().transact(new VoidWork() {
    public void vrun() {
    //save entity, this may throw - concurrent modification exception 
    }
});

If an exception is thrown, the vrun() method is called again. 如果引发异常,则再次调用vrun()方法。 I would like to log when this happens. 我想记录这种情况。 I have tried many things - surrounding the contents of vrun() with a try/catch, passing a reference to a boolean flag, etc. But this does not appear to work. 我已经尝试了很多事情-用try / catch包围vrun()的内容,传递对boolean标志的引用,等等。但这似乎不起作用。 Any ideas where I might be going wrong? 有什么想法我可能会出错吗?

I need to be able to programmatically detect if the transaction failed , and have some code execute before it is reattempted. 我需要能够以编程方式检测事务是否失败,并在重新尝试之前执行一些代码。

Use the overload for transactNew() that limits the # of tries: 将重载用于限制尝试次数的transactNew()

ofy().transactNew(1, new VoidWork() {
    ...
});

This will let you manage retries on your own. 这样您就可以自行管理重试。 Note that prior to v5.1.6, the # was erroneously being used as a # of retries (not tries). 请注意,在v5.1.6之前,该#错误地被用作#重试次数(不是尝试次数)。 In v5.1.6, behavior was corrected to match the documentation. 在v5.1.6中,行为已更正以匹配文档。 It's the # of tries. 这是尝试的次数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM