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)
主站蜘蛛池模板: 机械立体车库租赁_立体停车设备出租_智能停车场厂家_春华起重 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 | 精密线材测试仪-电线电缆检测仪-苏州欣硕电子科技有限公司 | 定制/定做冲锋衣厂家/公司-订做/订制冲锋衣价格/费用-北京圣达信 | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 继电器模组-IO端子台-plc连接线-省配线模组厂家-世麦德 | 云南标线|昆明划线|道路标线|交通标线-就选云南云路施工公司-云南云路科技有限公司 | 彭世修脚_修脚加盟_彭世修脚加盟_彭世足疗加盟_足疗加盟连锁_彭世修脚技术培训_彭世足疗 | 手机游戏_热门软件app下载_好玩的安卓游戏下载基地-吾爱下载站 | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | China plate rolling machine manufacturer,cone rolling machine-Saint Fighter | 浙江宝泉阀门有限公司 | 别墅图纸超市|别墅设计图纸|农村房屋设计图|农村自建房|别墅设计图纸及效果图大全 | 对夹式止回阀厂家,温州对夹式止回阀制造商--永嘉县润丰阀门有限公司 | 粘度计维修,在线粘度计,二手博勒飞粘度计维修|收购-天津市祥睿科技有限公司 | 变色龙PPT-国内原创PPT模板交易平台 - PPT贰零 - 西安聚讯网络科技有限公司 | 雨燕360体育免费直播_雨燕360免费NBA直播_NBA篮球高清直播无插件-雨燕360体育直播 | 全自动烧卖机厂家_饺子机_烧麦机价格_小笼汤包机_宁波江北阜欣食品机械有限公司 | 瓶盖扭矩测试仪-瓶盖扭力仪-全自动扭矩仪-济南三泉中石单品站 | 一级建造师培训_一建培训机构_中建云筑建造师培训网校 | 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 南京种植牙医院【官方挂号】_南京治疗种植牙医院那个好_南京看种植牙哪里好_南京茀莱堡口腔医院 尼龙PA610树脂,尼龙PA612树脂,尼龙PA1010树脂,透明尼龙-谷骐科技【官网】 | 【灵硕展览集团】展台展会设计_展览会展台搭建_展览展示设计一站式服务公司 | 西门子代理商_西门子变频器总代理-翰粤百科 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | 食品级焦亚硫酸钠_工业级焦亚硫酸钠_焦亚硫酸钠-潍坊邦华化工有限公司 | 电动葫芦|环链电动葫芦-北京凌鹰名优起重葫芦 | 桐城新闻网—桐城市融媒体中心主办 | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 大流量卧式砂磨机_强力分散机_双行星双动力混合机_同心双轴搅拌机-莱州市龙跃化工机械有限公司 | 步入式高低温测试箱|海向仪器| 衬塑管道_衬四氟管道厂家-淄博恒固化工设备有限公司 | 橡胶电子拉力机-塑料-微电脑电子拉力试验机厂家-江苏天源 | 模具硅橡胶,人体硅胶,移印硅胶浆厂家-宏图硅胶科技 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 今日热点_实时热点_奇闻异事_趣闻趣事_灵异事件 - 奇闻事件 |