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

How print or debug chef attributes?
Java: Other possible forms for return statement
Android NullPointerException on button click [duplicate]
Writing a JerseyTest for an external tomcat server
Android action overflow drawn on top of ActionBar
I couldn't get correct answer for my code [closed]
Android Mysql get specific data from table
Java 8 TYPE_USE annotations not behaving if array is annotated inside List or Map
From LoginActivity to HomeActivity (Android/Java)
Using a pre-made C++ library in Java using JNI
JPanel/JButtons disappear after JFrame addition of background image
How is RecordReader initialize invoked in MapReduce API?
Multiple Word Highlighting in Java
Multiple keybindings on one key?
Trouble passing parameters
Main thread doing too much work even though I use an async thread (laggy UI)

Categories

HOME
sendgrid
hive
zeromq
image-processing
c#-4.0
server
dictionary
office365api
sd-card
octobercms
infragistics
graphql
webpack-2
sql-server-2016
disassembler
ebean
yum
esper
google-translate
gorm
floating-action-button
dtrace
visual-studio-cordova
caml
clojurescript
systemc
angular-ui
google-pagespeed
autocad-plugin
cx-freeze
intentfilter
language-agnostic
restful-authentication
crosstab
opennlp
shopware
vlsi
poltergeist
bootstrap-duallistbox
phpfox
fgetcsv
maxmind
strncpy
subdomains
tasklet
.net-4.0
airconsole
create-table
fog
winrt-xaml-toolkit
caret
commit
form-data
ghost4j
normal-distribution
environment-modules
bytecode-manipulation
swisscomdev
x11-forwarding
code-search-engine
preconditions
ensembles
ruby-on-rails-3.1
ibpy
spring-security-kerberos
reactive-cocoa-5
websphere-mq-fte
jsch
fault
youcompleteme
strptime
upstart
komodoedit
domain-model
hls.js
google-perftools
nsarray
namecoin
pearson
jquery-filter
setuptools
android-fonts
instant
gridpane
mikroc
angstrom-linux
sdf
rvest
php-internals
thredds
dukescript
browser-bugs
0xdbe
nsight
angular-local-storage
qpainter
mdt
java-metro-framework
html-helper
document-classification
flask-cors
xsockets.net
bulkloader
pushbackinputstream
free-variable
rdoc
newtonscript
enter
reddot
semantic-diff
code-cleanup
punbb
horizontal-accordion
dentrix
ext3
memory-size
noscript
genealogy
data-acquisition
3gp
misv

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