Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


Question 107: What is Concurrent HashMap?



Download 7,31 Mb.
Pdf ko'rish
bet81/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   77   78   79   80   81   82   83   84   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 107: What is Concurrent HashMap?
Answer: ConcurrentHashMap class provides concurrent access to
the map, this class is very similar to HashTable, except that
ConcurrentHashMap provides better concurrency than HashTable or
even synchronizedMap.
Some points to remember:
ConcurrentHashMap is internally divided into segments, by
default size is 16 that means, at max 16 threads can work
at a time
Unlike HashTable, the entire map is not locked while
reading/writing from the map
In ConcurrentHashMap, concurrent threads can read the
value without locking
For adding or updating the map, the lock is obtained on
segment level, that means each thread can work on each
segment during high concurrency
Concurrency level defines a number, which is an estimated
number of threads concurrently accessing the map
ConcurrentHashMap does not allow null keys or null values
put() method acquires lock on the segment
get() method returns the most recently updated value
iterators returned by ConcurrentHashMap are fail-safe and
never throw ConcurrentModificationException
Question 108: What is HashSet class and how it
works internally?
Answer: HashSet is a class in Java that implements the Set Interface
and it allows us to have the unique elements only. HashSet class
does not maintain the insertion order of elements, if you want to
maintain the insertion order, then you can use LinkedHashSet.
Internal implementation of HashSet:


HashSet internally uses HashMap and as we know the keys are
unique in hashmap, the value passed in the add() method of
HashSet is stored as the key of hashmap, that is how Set maintains
the unique elements.
/**
* Constructs a new, empty set; the backing

HashMap

instance has
* default initial capacity (16) and load factor
(0.75).
*/

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   77   78   79   80   81   82   83   84   ...   89




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish