pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

什么是故障安全&Java中的快速失敗迭代器

What are fail-safe amp; fail-fast Iterators in Java(什么是故障安全amp;Java中的快速失敗迭代器)
本文介紹了什么是故障安全&Java中的快速失敗迭代器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

Java 中有兩種類型的迭代器:fail-safe 和 fail-fast.

There are two types of iterators in Java: fail-safe and fail-fast.

這是什么意思,它們之間有什么區別?

What does this mean, and is the difference between them?

推薦答案

它們有什么區別...

What is the difference between them ...

故障安全"(在工程中)意味著某事以一種不會造成損害或造成損害最小的方式發生故障.嚴格來說,在 Java 中不存在作為故障安全迭代器的東西.如果迭代器失敗(通常意義上的失敗"),您可以預期會發生損壞.

"Fail-safe" (in engineering) means that something fails in a way that causes no or minimal damage. Strictly speaking, there is no such thing in Java as a fail-safe iterator. If an iterator fails (in the normal sense of "fail"), you can expect damage to occur.

我懷疑你的意思實際上是弱一致".迭代器.javadoc 說:

I suspect that you actually mean "weakly consistent" iterators. The javadoc says:

大多數并發 Collection 實現(包括大多數隊列)也不同于通常的 java.util 約定,因為它們的 Iterators 和 Spliterators 提供弱一致而不是快速失敗遍歷."p>

通常,弱一致性意味著如果集合與迭代同時被修改,則迭代所看到的內容的保證會更弱.(詳細信息將在每個并發集合類 javadocs 中指定.)

Typically, weak consistency means that if a collection is modified concurrently with an iteration, the guarantees of what the iteration sees are weaker. (The details will be specified in each concurrent collection classes javadocs.)

快速失敗"(在系統設計中)表示積極檢查故障條件,以便故障條件(在可能的情況下1)在造成過多損壞之前檢測到.在 Java 中,快速失敗的迭代器會因拋出 ConcurrentModificationException 而失敗.

"Fail-fast" (in systems design) means that the failure condition is checked aggressively so that the failure condition is (where possible1) detected before too much damage can be done. In Java, a fail-fast iterator fails by throwing a ConcurrentModificationException.

快速失敗"的替代方案;和弱一致"是迭代失敗不可預測的語義;例如有時給出錯誤的答案或拋出意外的異常.(這是早期 Java 版本中 Enumeration API 的一些標準實現的行為.)

The alternative to "fail-fast" and "weakly consistent" is semantic where the iteration fails unpredictably; e.g. to sometimes give the wrong answer or throw an unexpected exception. (This was the behavior of some standard implementations of the Enumeration API in early versions of Java.)

...它們與我們用于收集的迭代器有什么不同.

... and are they different from the iterator we use for collection.

沒有.這些是標準集合類型實現的迭代器的屬性;即它們要么快速失敗",要么快速失敗".或弱一致"... 在同步和 Java 內存模型方面正確使用時1.

No. These are properties of the iterators implemented by standard Collection types; i.e. they are either "fail fast" or "weakly consistent" ... when used correctly with respect to synchronization and the Java memory model1.

快速失敗的迭代器通常使用集合對象上的 volatile 計數器實現.

Fail-fast iterators are typically implemented using a volatile counter on the collection object.

  • 當集合更新時,計數器會增加.
  • 創建Iterator時,計數器的當前值嵌入到Iterator對象中.
  • 當執行 Iterator 操作時,該方法會比較兩個計數器值,如果它們不同則拋出 CME.
  • When the collection 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.

相比之下,弱一致性迭代器通常是輕量級的,并利用每個并發集合的內部數據結構的屬性.沒有通用模式.如果您有興趣,請閱讀不同集合類的源代碼.

By contrast, weakly consistent iterators are typically light-weight and leverage properties of each concurrent collection's internal data structures. There is no general pattern. If you are interested, read the source code for different collection classes.

1 - 快速失敗迭代器行為假設應用程序在同步和內存模型方面已正確實現.(換句話說,應用程序 是線程安全的.)例如,如果您在沒有正確同步的情況下迭代 ArrayList,快速失敗"會導致機制應該檢測并發修改(盡管不能保證),但可能無法防止由于應用程序的不安全行為而損壞列表.為了說明,javadoc for Vector.iterator() 是這樣說的:

1 - The rider is that fail-fast iterator behavior assumes that the application is correctly implemented with respect to synchronization and the memory model. (In other words, the application is thread-safe.) For example, if you iterated an ArrayList without proper synchronization, the "fast fail" mechanism should detect the concurrent modification (though that isn't guaranteed), but may not prevent the list from being corrupted due to the application's unsafe behavior. To illustrate, the javadoc for Vector.iterator() says this:

無法保證迭代器的快速失敗行為,因為一般來說,在存在不同步的并發修改的情況下無法做出任何硬保證.快速失敗的迭代器會盡最大努力拋出 ConcurrentModificationException.因此,編寫一個依賴此異常來確保其正確性的程序是錯誤的:迭代器的快速失敗行為應僅用于檢測錯誤."

"The fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs."

這篇關于什么是故障安全&Java中的快速失敗迭代器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 定坤静电科技静电消除器厂家-除静电设备 | 涂层测厚仪_光泽度仪_uv能量计_紫外辐照计_太阳膜测试仪_透光率仪-林上科技 | 节流截止放空阀-不锈钢阀门-气动|电动截止阀-鸿华阀门有限公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 南京欧陆电气股份有限公司-风力发电机官网 | 衢州装饰公司|装潢公司|办公楼装修|排屋装修|别墅装修-衢州佳盛装饰 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 12cr1mov无缝钢管切割-15crmog无缝钢管切割-40cr无缝钢管切割-42crmo无缝钢管切割-Q345B无缝钢管切割-45#无缝钢管切割 - 聊城宽达钢管有限公司 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 液压油缸-液压缸厂家价格,液压站系统-山东国立液压制造有限公司 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 美甲贴片-指甲贴片-穿戴美甲-假指甲厂家--薇丝黛拉 | 碳纤维复合材料制品生产定制工厂订制厂家-凯夫拉凯芙拉碳纤维手机壳套-碳纤维雪茄盒外壳套-深圳市润大世纪新材料科技有限公司 | 济南保安公司加盟挂靠-亮剑国际安保服务集团总部-山东保安公司|济南保安培训学校 | 地源热泵一体机,地源热泵厂家-淄博汇能环保设备有限公司 | 高压油管,液压接头,液压附件-烟台市正诚液压附件 | CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 展厅装修公司|企业展厅设计|展厅制作|展厅搭建—广州展厅装饰公司 | 货车视频监控,油管家,货车油管家-淄博世纪锐行电子科技 | 旋振筛_不锈钢旋振筛_气旋筛_旋振筛厂家—新乡市大汉振动机械有限公司 | 合肥礼品公司-合肥礼品定制-商务礼品定制公司-安徽柏榽商贸有限公司 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 防火窗_耐火窗_防火门厂家_防火卷帘门-重庆三乐门业有限公司 | 水环真空泵厂家,2bv真空泵,2be真空泵-淄博真空设备厂 | 卫生型双针压力表-高温防腐差压表-安徽康泰电气有限公司 | 阜阳在线-阜阳综合门户| 2025福建平潭岛旅游攻略|蓝眼泪,景点,住宿攻略-趣平潭网 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 球形钽粉_球形钨粉_纳米粉末_难熔金属粉末-广东银纳官网 | 山东信蓝建设有限公司官网 | 蜘蛛车-高空作业平台-升降机-高空作业车租赁-臂式伸缩臂叉装车-登高车出租厂家 - 普雷斯特机械设备(北京)有限公司 | 谷歌关键词优化-外贸网站优化-Google SEO小语种推广-思亿欧外贸快车 | 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 不锈钢/气体/液体玻璃转子流量计(防腐,选型,规格)-常州天晟热工仪表有限公司【官网】 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 地磅-地秤-江阴/无锡地磅-江阴天亿计量设备有限公司_ | 蓝莓施肥机,智能施肥机,自动施肥机,水肥一体化项目,水肥一体机厂家,小型施肥机,圣大节水,滴灌施工方案,山东圣大节水科技有限公司官网17864474793 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 |