top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can you explain the difference between fail fast iterator and fail safe iterator ?

+1 vote
260 views
Can you explain the difference between fail fast iterator and fail safe iterator ?
posted Jan 7, 2015 by Roshni

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Fail fast iterator : This iterator throws "ConcurrentModificationException" when a thread iterating a collection realizes that the same collection is modified by another thread while under operation. Iterator identifies change in collection is by looking at it's modification count. Ex: HashMap

Fail safe iterator : If we are using fails safe iterator, the above scenario is handled and java doesn't throw the ConcurrentModificationException. To handle this scenario, iterator makes a clone of the collection and works on it. Ex: ConcurrentHashMap

answer Jan 8, 2015 by Karthick.c
...