茗赏玄米茶怎么样:Fail-fast

来源:百度文库 编辑:九乡新闻网 时间:2024/07/07 12:18:03

Fail-fast is a property of a system or module with respect to its response to failures. A fail-fast system is designed to immediately report at its interface any failureor condition that is likely to lead to failure. Fail-fast systems areusually designed to stop normal operation rather than attempt tocontinue a possibly-flawed process. Such designs often check thesystem's state at several points in an operation, so any failures can bedetected early. A fail-fast module passes the responsibility forhandling errors, but not detecting them, to the next-higher system design level.

Fail-fast systems or modules are desirable in several circumstances:

  • When building a fault-tolerant system by means of redundant components, the individual components should be fail-fast to give the system enough information to successfully tolerate a failure.
  • Fail-fast components are often used in situations where failure in one component might not be visible until it leads to failure in another component.
  • Finding the cause of a failure is easier in a fail-fast system, because the system reports the failure with as much information as possible as close to the time of failure as possible. In a fault-tolerant system, the failure might go undetected, whereas in a system that is neither fault-tolerant nor fail-fast the failure might be temporarily hidden until it causes some seemingly-unrelated problem later.
  • A fail-fast system that is designed to halt as well as report the error on failure is less likely to erroneously perform an irreversible or costly operation.

Examples

From the field of software engineering, a Fail Fast Iterator is an Iterator that attempts to raise an error if the sequence of elements processed by the Iterator is changed during Iteration.

See also

  • Failing badly vs. failing well
  • Fail-safe
  • Fail-stop

External links

  • "WHY DO COMPUTERS STOP AND WHAT CAN BE DONE ABOUT IT?" Article by Jim Gray introducing 'Fail Fast'
  • "Fail Fast" Article by Jim Shore explaining using 'Fail Fast' concept in software development (from 'columns for IEEE software' edited by Martin Fowler)
Retrieved from "http://en.wikipedia.org/wiki/Fail-fast"Categories: Failure | Software engineering terminology | Programming principles
another article
A structural modification is any operation that adds or deletes one ormore elements, or explicitly resizes the backing array; merely settingthe value of an element is not a structural modification.
  fail-fast: if the list is structurally modified at any time afterthe iterator is created, in any way except through the iterator's ownremove or add methods, the iterator will throw aConcurrentModificationException. Thus, in the face of concurrentmodification, the iterator fails quickly and cleanly, rather thanrisking arbitrary, non-deterministic behavior at an undetermined time inthe future.

Note that the fail-fast behavior of an iterator cannot be guaranteedas it is, generally speaking, impossible to make any hard guarantees inthe presence of unsynchronized concurrent modification. Fail-fastiterators throw ConcurrentModificationException on a best-effort basis.Therefore, it would be wrong to write a program that depended on thisexception for its correctness: the fail-fast behavior of iteratorsshould be used only to detect bugs.

    继承自AbstractList的List:LinkedList,ArrayList,Vector,Stack的Iterator都有这种属性
     PriorityQueue的Iterator也有这种属性.
     HashMap,HashSet都是


    中种特性的实现方法是借助于一个modCount成员变量,记录structualmodification的次数,在Iterator初始化时,让它的成员变量expectedModCount等于modCount,这样在Iterator做遍历时,如果发现 expectedModCount!=modCount就说明容器的内容发生了改变,抛出ConcurrentModificationException异常