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


Question 69: What is Garbage Collection in Java



Download 7,31 Mb.
Pdf ko'rish
bet50/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   46   47   48   49   50   51   52   53   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 69: What is Garbage Collection in Java,
how it works and what are the different types of
Garbage Collectors?
Answer: Garbage collection in java is the process of looking at heap
memory, identifying which objects are in use and which are not and
deleting the unused objects. An unused object or unreferenced
object, is no longer referenced by any part of your program.
Garbage collector is a daemon thread that keeps running in the
background, freeing up heap memory by destroying the unreachable
objects.
There was an analysis done on several applications which showed
that most objects are short lived, so this behavior was used to
improve the performance of JVM. In this method, the heap space is
divided into smaller parts or generations. These are, Young
Generation , Old or Tenured Generation and Permanent
Generation .
The Young Generation is where all new objects are allocated and
aged. The young generation is further divided into 3 parts: Eden
Space, Survivor space S0 and Survivor space S1. When the young
generation fills up, this causes a minor garbage collection . Some
surviving objects are aged and eventually move to the old
generation. All minor garbage collections are "Stop the World"
events. This means that all application threads are stopped until the
operation completes. Minor garbage collections are always Stop the
World events.
The Old Generation is used to store long surviving objects.
Typically, a threshold is set for young generation object and when
that age is met, the object gets moved to the old generation.
Eventually the old generation needs to be collected. This event is
called a major garbage collection . Major garbage collection are


also Stop the World events. Often a major collection is much slower
because it involves all live objects. So, for Responsive applications,
major garbage collections should be minimized. Also note that the
length of the Stop the World event for a major garbage collection is
affected by the kind of garbage collector that is used for the old
generation space.
The Permanent generation contains metadata required by the JVM
to describe the classes and methods used in the application. The
permanent generation is populated by the JVM at runtime based on
classes in use by the application. In addition, Java SE library classes
and methods may be stored here.
Classes may get collected (unloaded) if the JVM finds they are no
longer needed and space may be needed for other classes. The
permanent generation is included in a full garbage collection. And
Perm Gen was available till Java 7, it is removed from Java 8
onwards and JVM uses native memory for the representation of
class metadata which is called MetaSpace.
There is a flag MaxMetaspaceSize, to limit the amount of memory
used for class metadata. If we do not specify the value for this, the
Metaspace re-sizes at runtime as per the demand of the running
application.

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   46   47   48   49   50   51   52   53   ...   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