Fail safe vs Fail fast

转载 2015年07月10日 10:48:14

“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.)

Fail Fast Vs Fail Safe

原文Fail Fast And Fail Safe Iterators In Java :java中的迭代器使我们能够遍历Collection对象。 集合返回的迭代器本质上是Fail Fast的或 F...

java中fail-fast 和 fail-safe的区别

原文地址:http://javahungry.blogspot.com/2014/04/fail-fast-iterator-vs-fail-safe-iterator-difference-with...
  • ch717828
  • ch717828
  • 2015年07月15日 13:39
  • 10744

夜谈 Java中 Fail-fast 和 Fail-safe 的原理与使用

在我们详细讨论这两种机制的区别之前,首先得先了解并发修改。 1.什么是同步修改? 当一个或多个线程正在遍历一个集合Collection,此时另一个线程修改了这个集合的内容(添加,删除或者修改)。这...

Java Collection的Fail fast与Fail safe迭代器

Java中Fail fast与Fail safe迭代器的区别

java Collection中fail-fast 、fail-safe

转载自:http://blog.csdn.net/ch717828/article/details/46892051 在我们详细讨论这两种机制的区别之前,首先得先了解并发修改。1.什么是同步修改?当...

Oracle和Fail Safe安装配置指南

  • 2011年12月03日 22:36
  • 782KB
  • 下载

virtualbox安装centos7虚拟机,yum update出现safe thing yum can do is fail

也算是第一次真正的在虚拟机上装centos7虚拟机,之前在腾讯买云服务器也装的centos7,感觉还是挺好用的,装完之后发现输入yum update 命令出现safe thing yum can d...

oracle fail safe解决方案

  • 2008年12月09日 10:13
  • 956KB
  • 下载

Java Collections中的Fail Fast机制

  • 2007年04月05日 13:44
  • 220KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Fail safe vs Fail fast
举报原因:
原因补充:

(最多只允许输入30个字)