java


Why does the iterator print different output (related to failsafe)?


Why does the iterator print different output (related to failsafe)?
public class failSafe {
public static void main(String[] args) {
Map<Integer,Integer> student = new ConcurrentHashMap<>();
//Defining a new HashMap
student.put(3, 5);
student.put(2,10);
Iterator<Integer> itr = student.keySet().iterator();
while(itr.hasNext()){
System.out.println(student.get(itr.next()));
//student.put(4,40); will print 40 also
student.put(1,89);
//will not print 89.
}
`` }
}
The iterator of a ConcurrentHashMap is not fail-safe. It is weakly consistent. It guarantees to act on the snapshot of elements at the moment of its creation as the Javadocs states:
Similarly, Iterators, Spliterators and Enumerations return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration.
It does not guarantee reflecting newly added elements after its creation.

Related Links

Pause Button in Java Game
Reading from a file, running out of memory
How to I validated an input for being an Int and within a number range?
Program hangs on executeBatch()
Filtering XML Document using XPATH in java
Unable to import gpdraw in Java
Setting Android Manifest Tags Dynamically
Spring Security authentication from custom tables
Jackson API to store datetime
How to represent a response body in xml
JPA 2 Hibernate Group BY and Count * with other columns
HibernateSystemException: could not deserialize
Java8 LocalDateTime parsing error
Registering spring mvc controllers dynamically
Spring Batch CompositeItemWriter Transaction Roll back issue
Is there a way to remove a header in Grizzly server?

Categories

HOME
twitter
listview
openmp
webpack
push-notification
react-virtualized
react-router
octobercms
youtube-api-v3
survey
win32gui
icloud
sql-server-2016
windows-server
adfs
gorm
ssl-client-authentication
here-api
mapserver
quickfix
django-simple-history
django-admin
nhibernate-envers
google-cloud-speech
introduction
predix
object-detection
riot.js
abi
mustache.php
vlsi
elasticsearch-net
directx-10
twilio-api
android-nestedscrollview
io-redirection
webdriver-manager
elasticsearch-plugin
mapzen
g-code
google-closure
node-gyp
estimote
checkboxlist
cubic-spline
network-flow
filepicker
apache-fop
pango
clean-architecture
vtigercrm
nested-sets
heidisql
libpng
rotativa
slicknav
elements
login-control
contact-list
jwplayer7
moveit
sigabrt
dataview
r-tree
execute
msys
graph-drawing
cisco-ios
csquery
python-green
website-monitoring
block-device
offloading
cdt
id3v2
rdl
picturefill
farseer
jsctypes
runtime.exec
qt-faststart
mt
netdna-api
gcj
appendto
html-input
google-friend-connect
asp.net-profiles
sef
text-coloring
port-number
w3wp
3gp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App