关闭

Fail safe vs Fail fast

标签: safefail
458人阅读 评论(0) 收藏 举报
分类:

“Fail safe” means: it won’t fail.
“Fail fast” means: it may fail(只是有可能,所以,有时也不会fail,例如你在使用iterator遍历到数组的最后一个元素时,数组被删除了一个元素,这时候是不会fail的) … and the failure condition is checked aggressively so that the failure condition is detectedbefore damage can be done.
The alternative to “fail safe” and “fail fast” is to fail unpredictably; e.g. to sometimes give the wrong answer or throw some unexpected exception. (This was the behaviour of some standard implementations of the Enumeration API in early versions of Java.)
… and are they different from the iterator we use for collection.
No. These are properties of the Iterators implemented by standard Collection types; i.e. they are either “fail fast” or “fail safe” … when used correctly with respect to synchronization and the Java memory model. (By contrast, if you use an non-concurrent Iterator or Collection without the correct external synchronization, all bets are off …)
Also what is the name of iterator we normally use to iterate.
Umm … the actual class name depends on how you got the Iterator, as do the Iterator’s properties; e.g. “fail fast” versus “fail safe”. For the standard classes and iterators obtained using the iterator() method, the properties are specified by the collection classes javadocs.
… how are they implemented.
The fail-fast iterators are typically implemented using a volatile counter on the list object.

* When the list is updated, the counter is incremented.
* When an Iterator is created, the current value of the counter is embedded in the Iterator object.
* When an Iterator operation is performed, the method compares the two counter values and throws a CME if they are different.

The implementation of fail-safe iterators is typically light-weight. They typically rely on properties of the specific list implementation’s data structures. There is no general pattern. (Read the source code for the specific cases you are interested in.)

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:609777次
    • 积分:10044
    • 等级:
    • 排名:第1701名
    • 原创:377篇
    • 转载:267篇
    • 译文:1篇
    • 评论:33条
    文章分类
    最新评论