Diff for "LogOnJava/Vector and its fail-fast iterator"

Differences between revisions 2 and 0

Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
!'''[http://generic-viagra.land.ru/ | Generic viagra online] !'''
!'''[http://cheap-phentermine.hotmail.ru/ | buy phentermine cheap phentermine online] !'''
!'''[http://best-phentermine.hotmail.ru/ | buy cheap phentermine online] !'''
!'''[http://fha_mortgage.chat.ru/ | buy cheap phentermine online] !'''
!'''[http://ticket1_broker.chat.ru/ | Ticket Broker] !'''
!'''[http://buy_phent.chat.ru/ | buy adipex phentermine] !'''
!'''[http://cheap--viagra.fromru.com/ | Cheap viagra] !'''!
#acl YoonKyungKoo:read,write All:read
== TIP : Vector 와 Iterator, Enumeration ==
Line 9: Line 4:
!'''[http://united-airline.boom.ru/ | United Airlines tickets flights] !'''!
!'''[http://computer-desk.fromru.com/ | Computer desk] !'''!
java.util.Vector 클래스는 java.util.ArrayList와 비교되어 많이 사용되는 클래스이다.
Line 12: Line 6:
[http://online1degree.chat.ru/ | Online degree]
[http://camel-cig.newmail.ru | Cheap camel cigarettes]
[http://marlb-cigarette.newmail.ru | marlboro cigarettes]
[http://gift_basket.chat.ru/ | Gift basket]
[http://find-tires.com/ | Best Tires]
[http://cisco_forum.chat.ru/ | cisco forum]
[http://cisco_router_use.chat.ru/ | cisco router used]
[http://cisco_switch.chat.ru/ | cisco switch]
[http://adler_cisco.chat.ru/ | adler cisco]
[http://cisco_training.chat.ru/ | cisco training]
[http://cisco8_equipment.chat.ru/ | cisco equipment used]
[http://cisco_networking.chat.ru/ | cisco networking]
[http://cisco_college_ju.chat.ru/ | cisco college junior]
[http://cisco_college_jr.chat.ru/ | cisco college jr]
[http://cable_cisco.chat.ru/ | cable cisco]
[http://cisco_switch_use.chat.ru/ | cisco switch used]
[http://cisco_refurbishe.chat.ru/ | cisco refurbished]
[http://buy_cisco_router.chat.ru/ | buy cisco router]
[http://certification_ci.chat.ru/ | certification cisco]
[http://cisco_phone_voip.chat.ru/ | cisco phone voip]
[http://cisco_ip_phone.chat.ru/ | cisco ip phone]
[http://catalyst_cisco.chat.ru/ | catalyst cisco]
[http://cisco_memory_rou.chat.ru/ | cisco memory router]
[http://ccna_cisco.chat.ru/ | ccna cisco]
[http://cisco_firewall_p.chat.ru/ | cisco firewall pix]
[http://cisco_firewall_s.chat.ru/ | cisco firewall statefull voip]
[http://cisco_voip.chat.ru/ | cisco voip]
[http://cheap_cisco_rout.chat.ru/ | cheap cisco router]
흔히 자바 개발자는 Vector 클래스는 동기화된 ArrayList, ArrayList 클래스는 동기화되지 않은 Vector 클래스로 인식한다.
Line 41: Line 8:
물론 틀리지 않았다.
Line 42: Line 10:
Best links: '''cisco ip telephony''' 그러면 Enumeration와 Iterator는?
흔히 Enumeration와 Iterator를 비교할 때에는 Enumeration 인터페이스는 메소드 이름들이 긴 Collection 이전 방식의 순차 인터페이스이고 Iterator 인터페이스는 메소드 이름들이 짧은 Collection 방식의 순차 인터페이스로 기억한다.
Line 44: Line 13:
[http://cisco_telephony.chat.ru/ | cisco ip telephony] 물론 틀리지 않았다.
Line 46: Line 15:
Vector 클래스가 List 인터페이스를 구현하고 있으므로 iterator() 메소드를 지원한다.
물론 Enumeration 인터페이스를 제공하는 elements() 메소드도 지원한다.
Line 47: Line 18:
Best links: '''classic car insurance''' 그럼 iterator()의 결과인 Iterator와 elements()의 결과인 Enumeration 인터페이스는 기능이 완전히 동일한 것일까?
Line 49: Line 20:
[http://classic-car-insurance.fromru.com/ | classic car insurance] '''그렇지 않다는 것이다.'''
Line 51: Line 22:
Vector에서 iterator() 메소드는 부모 클래스인 AbstractList의 것을 그대로 사용한다.
이 iterator() 메소드의 특징은 fail-fast라는 데 있다.
JavaDoc API 문서를 보면 다음과 같이 iterator() 메소드에 대해 설명하고 있다.
Line 52: Line 26:
Best links: '''cleaner''' {{{
 The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Vector's elements method are not fail-fast.
Line 54: Line 29:
[http://miele_vacleaner.chat.ru/ | miele vacuum cleaner] Note that 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.
}}}
Line 56: Line 32:
이 말을 간단하게 설명하면, Vector 클래스의 iterator() 메소드의 리턴값으로 받은 Iterator 인터페이스를 사용하여 순차하는 도중, 해당 Iterator 객체의 remove나 add가 아닌 다른 방식에 의해 Vector 클래스에 변경이 일어나면 ConcurrentModificationException 이라는 런타임 예외가 발생한다는 것이다.
Line 57: Line 34:
Best links: '''cleaning''' 이것이 원하는 결과가 아니라면... Enumeration을 사용하면 된다.
Line 59: Line 36:
[http://cleaning_product.chat.ru/ | cleaning product]
[http://cleaning_supply.chat.ru/ | cleaning supply]
[http://carpet_cleaning.chat.ru/ | carpet cleaning]
[http://cleaning_service.chat.ru/ | cleaning services]
[http://house_cleaning.chat.ru/ | house cleaning]
[http://steam_cleaning.chat.ru/ | steam cleaning]
[http://carpet_cleaning_.chat.ru/ | carpet cleaning machine]
[http://carpet3_cleaning.chat.ru/ | carpet cleaning supply]
[http://window_cleaning.chat.ru/ | window cleaning]
[http://roof_cleaning.chat.ru/ | roof cleaning]
[http://cleaning9.chat.ru/ | cleaning]
[http://hotel_cleaning_s.chat.ru/ | hotel cleaning supply]
[http://commercial_clean.chat.ru/ | commercial cleaning]
[http://cleaning_equipme.chat.ru/ | cleaning equipment]
[http://carpet2_cleaning.chat.ru/ | carpet cleaning equipment]
[http://office_cleaning.chat.ru/ | office cleaning]
[http://house6_cleaning.chat.ru/ | house cleaning]
[http://cleaningservice.chat.ru/ | cleaning services]
[http://carpet_cleanings.chat.ru/ | carpet cleaning supply]
[http://window4_cleaning.chat.ru/ | window cleaning]
[http://cleaning9_supply.chat.ru/ | cleaning supply]
[http://cleaning2_produc.chat.ru/ | cleaning product]
[http://cleaning3_equipm.chat.ru/ | cleaning equipment]
[http://carpet_cleaning2.chat.ru/ | carpet cleaning machine]
[http://dry_cleaning.chat.ru/ | dry cleaning]
[http://window_cleanings.chat.ru/ | window cleaning supply]
[http://dry_cleaning_ser.chat.ru/ | dry cleaning service]
[http://janitorial_clean.chat.ru/ | janitorial cleaning supply]
[http://office_cleanings.chat.ru/ | office cleaning supply]
[http://hotel3_cleaning.chat.ru/ | hotel cleaning supply]
[http://floor_cleaning_s.chat.ru/ | floor cleaning supply]
[http://carpet_clean_eq.chat.ru/ | carpet cleaning equipment]
[http://gutter6_cleaning.chat.ru/ | gutter cleaning]
[http://restaurant_clean.chat.ru/ | restaurant cleaning supply]
[http://office5_cleaning.chat.ru/ | office cleaning]
[http://chimney_cleaning.chat.ru/ | chimney cleaning]
[http://commercial5_clea.chat.ru/ | commercial cleaning supply]
[http://cleaning_tip.chat.ru/ | cleaning tip]
[http://colon_cleaning.chat.ru/ | colon cleaning]
[http://cleaning_busines.chat.ru/ | cleaning business]
[http://sofa_cleaning.chat.ru/ | sofa cleaning]
[http://commercial7_clea.chat.ru/ | commercial cleaning product]
[http://industrial_clean.chat.ru/ | industrial cleaning supply]
[http://furniture_cleani.chat.ru/ | furniture cleaning]
[http://duct_cleaning.chat.ru/ | duct cleaning]
[http://how_start_clbus.chat.ru/ | how to start a cleaning business]
[http://upholstery_clean.chat.ru/ | upholstery cleaning]
[http://drain_cleaning.chat.ru/ | drain cleaning]
[http://steam6_cleaning.chat.ru/ | steam cleaning]
[http://cleaning_franchi.chat.ru/ | cleaning franchise]
[http://grout_cleaning.chat.ru/ | grout cleaning]
[http://floor_cleaning.chat.ru/ | floor cleaning]
[http://car_cleaning.chat.ru/ | car cleaning]
[http://carpet_cleaning.fiberia.com/ | carpet cleaning]
[http://carpet2clean.fiberia.com/ | carpet cleaning]


Best links: '''club month'''

[http://club-month.boom.ru/ | club month]


Best links: '''code'''

[http://bar1_code.chat.ru/ | bar code]
[http://bar_code.chat.ru/ | bar code]
[http://bar-code.fromru.com/ | bar code]


Best links: '''coffee'''

[http://gourmet_coffee.chat.ru/ | gourmet coffee]
[http://gourmet-coffee.fromru.com/ | gourmet coffee]


Best links: '''computer desk'''

[http://computer1-desk.boom.ru/ | computer desk]
[http://computer1desk.chat.ru/ | computer desk]
[http://computer-desk.fromru.com/ | computer desk]


Best links: '''construction safety'''

[http://construction4_sa.chat.ru/ | construction safety program]
[http://construction_saf.chat.ru/ | construction safety]
[http://construction_sm.chat.ru/ | construction safety manual]
[http://construction_sp.chat.ru/ | construction safety plan]
[http://construction_hea.chat.ru/ | construction health and safety]
[http://construction_sit.chat.ru/ | construction site safety]


Best links: '''contact lense'''

[http://contact_lense.chat.ru/ | contact lense]
[http://contact-lense.pochta.ru/ | contact lense]
[http://contact_len.chat.ru/ | contact lense]
[http://contact-lens.pochta.ru/ | contact lense]


Best links: '''cosmetic'''

[http://botox_cosmetic.chat.ru/ | botox cosmetic]
[http://cosmetic1_dentis.chat.ru/ | cosmetic dentist california]
[http://cosmetic_dentist.chat.ru/ | cosmetic dentistry]
[http://cosmetic5_surger.chat.ru/ | cosmetic surgery]
[http://mac_cosmetic.chat.ru/ | mac cosmetic]
[http://philosophy_cosme.chat.ru/ | philosophy cosmetic]
[http://beauticontrol_co.chat.ru/ | beauticontrol cosmetic]
[http://cosmetic_bag.chat.ru/ | cosmetic bag]
[http://los_angeles_cosm.chat.ru/ | los angeles cosmetic surgery]
[http://cosmetic0_dentis.chat.ru/ | cosmetic dentist]
[http://mary_kay_cosmeti.chat.ru/ | mary kay cosmetic]
[http://cosmetic_surg.chat.ru/ | cosmetic surgeon]
[http://sephora_cosmetic.chat.ru/ | sephora cosmetic]
[http://clinique_cosmeti.chat.ru/ | clinique cosmetic]
[http://cosmetic_dentis.chat.ru/ | cosmetic dentist los angeles]
[http://bobbi_brown_cosm.chat.ru/ | bobbi brown cosmetic]
[http://skin_care_cosmet.chat.ru/ | skin care cosmetic]


Best links: '''counseling'''

[http://credit_counselin.chat.ru/ | credit counseling]
[http://debt_counseling.chat.ru/ | debt counseling]
[http://consumer_credit_.chat.ru/ | consumer credit counseling]
[http://credit_and_debt_.chat.ru/ | credit and debt counseling]
[http://debt4_consolidat.chat.ru/ | debt consolidation counseling]
[http://credit0_counseli.chat.ru/ | credit counseling service]
[http://consumer_debt_co.chat.ru/ | consumer debt counseling]
[http://marriage_counsel.chat.ru/ | marriage counseling]
[http://credit08_counsel.chat.ru/ | credit counseling services]
[http://career_counselin.chat.ru/ | career counseling]
[http://credit_card_coun.chat.ru/ | credit card counseling]
[http://consumer3_credit.chat.ru/ | consumer credit counseling service]
[http://com_counseling_c.chat.ru/ | com counseling credit en language site]
[http://debt2_consolidat.chat.ru/ | debt consolidation credit counseling]
[http://debt3_management.chat.ru/ | debt management credit counseling]
[http://counseling5_and_.chat.ru/ | counseling and management]
[http://credit8_card_deb.chat.ru/ | credit card debt counseling]
[http://school_counselin.chat.ru/ | school counseling]
[http://relationship_cou.chat.ru/ | relationship counseling]
[http://online_counselin.chat.ru/ | online counseling degree]
[http://debt_counseling_.chat.ru/ | debt counseling service]
[http://counseling_degre.chat.ru/ | counseling degree]
[http://christian_credit.chat.ru/ | christian credit counseling]
[http://credit4_counseli.chat.ru/ | credit counseling center]
[http://christian_debt_c.chat.ru/ | christian debt counseling]
[http://career_in_counse.chat.ru/ | career in counseling]
[http://counseling_test.chat.ru/ | counseling test]
[http://family_counselin.chat.ru/ | family counseling]
[http://american_school_.chat.ru/ | american school counseling association]


Best links: '''course'''

[http://college1_course.chat.ru/ | college course online]
[http://golf0_course.chat.ru/ | golf course]
[http://course9_online.chat.ru/ | course online]
[http://online9_criminal.chat.ru/ | online criminal justice course]
[http://online_compc.chat.ru/ | online computer course]
[http://correspondence_c.chat.ru/ | correspondence course]
[http://gmat_course.chat.ru/ | gmat course]
[http://real_estate_cour.chat.ru/ | real estate course]
[http://online7_educatio.chat.ru/ | online education course]
[http://distance6_learni.chat.ru/ | distance learning course]
[http://course_ii_online.chat.ru/ | course ii online]
[http://computer_course.chat.ru/ | computer course]
[http://web_course.chat.ru/ | web course]
[http://defensive_drivc.chat.ru/ | defensive driving course]
[http://army_corresponde.chat.ru/ | army correspondence course]
[http://course_informati.chat.ru/ | course information]
[http://college_course.chat.ru/ | college course]
[http://course_home.chat.ru/ | course home]
[http://private8_golf_co.chat.ru/ | private golf course]
[http://golf_course_dall.chat.ru/ | golf course dallas]
[http://online_paralegc.chat.ru/ | online paralegal course]
[http://golf_course_chic.chat.ru/ | golf course chicago]
[http://golf_course_publ.chat.ru/ | golf course public]
[http://home_study_cours.chat.ru/ | home study course]
[http://golf_course_phoe.chat.ru/ | golf course phoenix]
[http://course_technolog.chat.ru/ | course technology]
[http://online_high_scho.chat.ru/ | online high school course]
[http://education8_cours.chat.ru/ | education course]
[http://golf_course_detr.chat.ru/ | golf course detroit]
[http://training0_course.chat.ru/ | training course]
[http://spanish_course.chat.ru/ | spanish course]
[http://free_online_cour.chat.ru/ | free online course]
[http://las_vegas_golf_c.chat.ru/ | las vegas golf course]
[http://english_course.chat.ru/ | english course]
[http://rope_course.chat.ru/ | rope course]


Best links: '''courses'''

[http://college_online.euro.ru/ | college course online]
[http://army_course.chat.ru/ | army online courses]
[http://online-education-courses.fromru.com/ | online education course]


Best links: '''craps'''

[http://craps-rule.fromru.com/ | craps rule]
[http://craps_rule.chat.ru/ | craps rule]
[http://casino-craps.pochta.ru/ | casino craps]
[http://craps_online.chat.ru/ | craps online]
[http://craps-online.pochta.ru/ | craps online]
[http://craps2_rule.chat.ru/ | craps rule]
[http://craps-rule.pochta.ru/ | craps rule]
[http://craps_strategy.chat.ru/ | craps strategy]
[http://craps_table.chat.ru/ | craps table]
[http://craps-table.pochta.ru/ | craps table]
[http://craps_game.chat.ru/ | craps game]
[http://craps-game.pochta.ru/ | craps game]
[http://casino_craps.chat.ru/ | casino craps]
[http://craps_odds.chat.ru/ | craps odds]
[http://craps-odds.pochta.ru/ | craps odds]
[http://craps_free_play.chat.ru/ | craps free play]
[http://craps-free-play.pochta.ru/ | craps free play]
[http://craps-system.pochta.ru/ | craps system]
[http://craps_system.chat.ru/ | craps system]
[http://craps_free_downl.chat.ru/ | craps free download]
[http://craps--free-download.pochta.ru/ | craps free download]
[http://craps_download.chat.ru/ | craps download]
[http://craps-download.pochta.ru/ | craps download]
[http://craps_learn_play.chat.ru/ | craps learn play]
[http://craps-learn-play.pochta.ru/ | craps learn play]
[http://craps_custom_tab.chat.ru/ | craps custom table]
[http://craps-custom-table.pochta.ru/ | craps custom table]
[http://craps_free.chat.ru/ | craps free]
[http://craps-free.pochta.ru/ | craps free]
[http://craps_onlin_play.chat.ru/ | craps online play]
[http://craps-online-play.pochta.ru/ | craps online play]
[http://craps-free.fromru.com/ | craps free]
[http://craps_gambling.chat.ru/ | craps gambling]
[http://craps-gambling.pochta.ru/ | craps gambling]
[http://craps-gambling.land.ru/ | craps gambling]
[http://craps-online.fromru.com/ | craps online]
[http://craps-rule.land.ru/ | craps rule]
[http://craps-strategy.fromru.com/ | craps strategy]
[http://craps-table.land.ru/ | craps table]
[http://craps-game.fromru.com/ | craps game]
[http://casino-craps.land.ru/ | casino craps]
[http://craps_play.chat.ru/ | craps play]
[http://craps-play.pochta.ru/ | craps play]
[http://craps-play.fromru.com/ | craps play]
[http://craps-odds.land.ru/ | craps odds]
[http://craps_win.chat.ru/ | craps win]
[http://craps-win.pochta.ru/ | craps win]
[http://craps-win.fromru.com/ | craps win]
[http://craps_free_game.chat.ru/ | craps free game]
[http://craps-free-game.pochta.ru/ | craps free game]
[http://craps-free-game.fromru.com/ | craps free game]
[http://craps_game_onlin.chat.ru/ | craps game online]
[http://craps-game-online.pochta.ru/ | craps game online]
[http://craps-game-online.land.ru/ | craps game online]
[http://craps_free_onlin.chat.ru/ | craps free online]
[http://craps-free-online.pochta.ru/ | craps free online]
[http://craps-free-online.fromru.com/ | craps free online]
[http://craps_supply.chat.ru/ | craps supply]
[http://craps-supply.pochta.ru/ | craps supply]
[http://craps-supply.land.ru/ | craps supply]
[http://craps_internet.chat.ru/ | craps internet]
[http://craps-internet.pochta.ru/ | craps internet]
[http://craps-internet.land.ru/ | craps internet]
[http://casino_craps_onl.chat.ru/ | casino craps online]
[http://casino-craps-online.pochta.ru/ | casino craps online]
[http://casino-craps-online.fromru.com/ | casino craps online]
[http://craps_playing.chat.ru/ | craps playing]
[http://craps-playing.pochta.ru/ | craps playing]
[http://craps-playing.land.ru/ | craps playing]
[http://online-craps.fromru.com/ | online craps]
[http://craps_online1.chat.ru/ | online craps]


Best links: '''credit card'''

[http://accept_cred_card.chat.ru/ | accept credit card]
[http://accept-credit-card.fromru.com/ | accept credit card]


Best links: '''credit counseling'''

[http://credit1counselin.chat.ru/ | credit counseling]


Best links: '''credit help'''

[http://credit_help.chat.ru/ | credit help]


Best links: '''credit-report'''

[http://credit_report.chat.ru/ | credit-report]


Best links: '''cruise'''

[http://norwegiancruisel.chat.ru/ | norwegian cruise line]
[http://carnivalcruise.chat.ru/ | carnival cruise]
[http://caribbeancruise.chat.ru/ | caribbean cruise]
[http://pcruiseline.chat.ru/ | princess cruise line]
[http://cruisetravel.chat.ru/ | cruise travel]
[http://crystal1cruise.chat.ru/ | crystal cruise]
[http://costacruises.chat.ru/ | costa cruises]
[http://radissoncruise.chat.ru/ | radisson cruise]
[http://medit1cruise.chat.ru/ | mediterranean cruise]
[http://panama1cruise.chat.ru/ | panama canal cruise]
[http://cruisedeal.chat.ru/ | cruise deal]
[http://cruiseprincess.chat.ru/ | cruise princess]
[http://norwegiancruise.chat.ru/ | norwegian cruise]
[http://cruiseline.chat.ru/ | cruise line]
[http://cruiseship.chat.ru/ | cruise ship]
[http://discountcruises.chat.ru/ | discount cruises]
[http://honeymooncruise.chat.ru/ | honeymoon cruise]
[http://cruiseeuropean.chat.ru/ | cruise european]
[http://celebritycruise.chat.ru/ | celebrity cruise]
[http://lastminutecruise.chat.ru/ | last minute cruise]
[http://cruisespecial.chat.ru/ | cruise special]
[http://alaskacruise.chat.ru/ | alaska cruise]
[http://carnivalcruises.chat.ru/ | carnival cruise ship]
[http://newyorkcruises.chat.ru/ | new york cruises]
[http://cheapcruise.chat.ru/ | cheap cruise]
[http://hawaiicruises.chat.ru/ | hawaii cruise]
[http://cruisevacation.chat.ru/ | cruise vacation]
[http://disneycruise.chat.ru/ | disney cruise]
[http://hamericacruises.chat.ru/ | holland america cruises]
[http://familycruises.chat.ru/ | family cruises]
[http://bahamascruise.chat.ru/ | bahamas cruise]
[http://mexicocruise.chat.ru/ | mexico cruise]
[http://bermudacruise.chat.ru/ | bermuda cruise]
[http://europecruise.chat.ru/ | europe cruise]
[http://caribbeancruisel.chat.ru/ | caribbean cruise line]
[http://cruisepackage.chat.ru/ | cruise package]
[http://cruisereview.chat.ru/ | cruise review]
[http://carnivalcruisel.chat.ru/ | carnival cruise line]
[http://disneycruisel.chat.ru/ | disney cruise line]
[http://nilecruises.chat.ru/ | nile cruises]

[http://sympathy-giftb.fromru.com/ | sympathy gift basket] [http://baby-gb.pochta.ru/ | baby gift basket] [http://food_gb.chat.ru/ | food gift basket] [http://gourmet_gb.chat.ru/ | gourmet gift basket] [http://cookie_gift_b.chat.ru/ | cookie gift basket]
특히 여러 개의 쓰레드가 Vector 객체를 순차하기도 하고, 수정하기도 할 때, fail-fast 방식의 런타임 예외가 원하는 결과가 아니라 조용히 진행되길 원한다면 옛날 방식 인터페이스인 Enumeration을 사용해야 한다.

TIP : Vector 와 Iterator, Enumeration

java.util.Vector 클래스는 java.util.ArrayList와 비교되어 많이 사용되는 클래스이다.

흔히 자바 개발자는 Vector 클래스는 동기화된 ArrayList, ArrayList 클래스는 동기화되지 않은 Vector 클래스로 인식한다.

물론 틀리지 않았다.

그러면 Enumeration와 Iterator는? 흔히 Enumeration와 Iterator를 비교할 때에는 Enumeration 인터페이스는 메소드 이름들이 긴 Collection 이전 방식의 순차 인터페이스이고 Iterator 인터페이스는 메소드 이름들이 짧은 Collection 방식의 순차 인터페이스로 기억한다.

물론 틀리지 않았다.

Vector 클래스가 List 인터페이스를 구현하고 있으므로 iterator() 메소드를 지원한다. 물론 Enumeration 인터페이스를 제공하는 elements() 메소드도 지원한다.

그럼 iterator()의 결과인 Iterator와 elements()의 결과인 Enumeration 인터페이스는 기능이 완전히 동일한 것일까?

그렇지 않다는 것이다.

Vector에서 iterator() 메소드는 부모 클래스인 AbstractList의 것을 그대로 사용한다. 이 iterator() 메소드의 특징은 fail-fast라는 데 있다. JavaDoc API 문서를 보면 다음과 같이 iterator() 메소드에 대해 설명하고 있다.

 The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Vector's elements method are not fail-fast.

Note that 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.

이 말을 간단하게 설명하면, Vector 클래스의 iterator() 메소드의 리턴값으로 받은 Iterator 인터페이스를 사용하여 순차하는 도중, 해당 Iterator 객체의 remove나 add가 아닌 다른 방식에 의해 Vector 클래스에 변경이 일어나면 ConcurrentModificationException 이라는 런타임 예외가 발생한다는 것이다.

이것이 원하는 결과가 아니라면... Enumeration을 사용하면 된다.

특히 여러 개의 쓰레드가 Vector 객체를 순차하기도 하고, 수정하기도 할 때, fail-fast 방식의 런타임 예외가 원하는 결과가 아니라 조용히 진행되길 원한다면 옛날 방식 인터페이스인 Enumeration을 사용해야 한다.

last edited 2005-11-30 20:12:42 by YoonKyungKoo