故障快速和故障安全异常处理原则是否兼容? [英] Are fail-fast and fail-safe exception handling principles incompatible?

查看:194
本文介绍了故障快速和故障安全异常处理原则是否兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更好地了解什么是故障快速和故障安全。

I'd like to understand better what is fail-fast and fail-safe.

乍一看,我觉得,失败快速意味着当任何意想不到的事情发生时,我们希望让系统明显失败。
我的意思是说,如果一个工厂不能创建一个对象的实例,对于失败的原则,我们真的不希望工厂返回null,或空对象,或部分初始化的对象,可以通过机会,被应用程序正确使用 - >大多数时候我们会有一个意想不到的行为,或者在另一个级别引起意外的异常,这不能让我们知道工厂中的真正的事情。
这个原则是什么意思?

What it seems to me at first glance is that fail-fast means that we want to make the system clearly fail when any unexpected thing happens. I mean for exemple if a factory can't create an instance of object, for fail-fast principle, we really don't want the factory to return null, or empty object, or partially initialized object that could, by chance, be used correctly by the application -> most time we would have an unexpected behaviour, or an unexpected exception raised at another level that wouldn't permit us to know the real matter is in the factory. It is what this principle means?

失败的安全原则对我来说很难理解。
Java中最常见的例子是关于集合,它们的迭代器和并发访问。
据说,一个允许在遍历它的过程中修改列表的集合/迭代器称为故障安全。通常通过最后迭代初始列表的副本来完成。
但是在这个例子中,我不太明白系统在哪里失败...因此,它是故障安全的...失败在哪里?我们只是根据我们的需要迭代一个副本...
我没有看到任何匹配的维基定义的故障安全...

Fail safe principle is quite hard to understand for me. The most common exemple in Java is about the collections, their iterators and the concurrent access. It's said that a collection/iterator that permits modifying a list while iterating over it is called fail-safe. It's usually done by finally iterating over a copy of the initial list. But in this exemple i don't really understand where the system fails... and thus while it's fail-safe... Where is the failure? We just iterate over a copy or not, depending on our needs... I don't see any match with the wiki definition of fail-safe...

因此,在这样的文章中,如:
http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-fail-safe/
他们相反的故障快速到故障安全..我只是不知道为什么我们在一个副本上调用失败保护这个迭代...

Thus in such articles like: http://www.certpal.com/blogs/2009/09/iterators-fail-fast-vs-fail-safe/ They opposite fail-fast to fail-safe... what i just don't catch is why we call fail-safe this iteration over a copy...

我在这里找到另一个例子:
http://tutorials.jenkov.com/java-exception-handling /fail-safe-exception-handling.html
它似乎与故障安全原则的初始定义有关。
我认为故障安全是当系统发生故障时,我们必须确保故障处理程序不会失败,否则确保真正的初始问题不会被处理程序的失败隐藏。在给定的例子中,处理程序正好在初始失败代码附近,但并不总是如此。故障安全意味着给我更多的东西,像我们正确地处理在故障处理程序或类似的东西可能发生的错误...

I found another exemple here: http://tutorials.jenkov.com/java-exception-handling/fail-safe-exception-handling.html It seems a lot more related to initial definition of the fail-safe principle. What i think of fail-safe is that when a system fails, we must ensure that the failure handler doesn't fail or, if it does, ensure that the real initial problem is not hidden by the failure of the handler. In the given exemple the handler is right near the initial failure code, but it's not always the case. Fail-safe means to me more something like we handle correctly the errors that could happen in the failure handlers or something like that...

因此对于我这两个原则看起来不兼容
你觉得怎么样?
系统不能快速失败安全地

Thus for me these 2 principles doesn't seem incompatible. What do you think? Can't a system fail fast & safely???

推荐答案

最好先避免失败(故障安全),但是如果这是不可能的,最好尽快失败(尽快失败)。

It is better to avoid failure in the first place (fail safe), but if this is not possible, it is best to fail fast (to fail as quickly as possible).

这两个不是对立的,而是互补的。

The two are not opposites, but complementary.

正如你所说 - 我喜欢我的代码尽可能的失败,但不在的地方,我希望它能够快速失败。

As you say - I like my code to be as fail safe as possible, but where it isn't, I want it to fail fast.

这篇关于故障快速和故障安全异常处理原则是否兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆