Question: What is the significance of synchronized method/block?
Answer: Synchronized works on objects, meaning that only one thread can obtain lock on a certain instance of an object. Only one thread can execute synchronized block of code on a certain object. Example of such object is list that is accessed synchronized, so that multiple threads are accessing list without corrupting its contents.
Question: Explain JVM Memory Management.
Answer: Java manages memory in 3 different places:
Stack:
• Stacks holds method’s arguments, return value & local variable.
• FILO – First In Last Out basis. The life time of the stack members decide based on
scope.
• Initial stack size will be allocated by JVM if no arguments provide at start up.
•Stack using Push-Pop operation to manage its contents.
Static memory Area:
• This area holds all the static members of the class and also maintains run time constant pool. Run time constant pool is the table maintained by the JVM which holds string literals, constants etc.
• All the instances will share this location if multiple instances created for the class.
Heap :
• This place holds all the real live instances & Arrays – whatever we create using new key word will get physical memory in this place.
•JVM use Garbage Collector to manage this memory location.
•Initial Heap size will be allocated by JVM if no arguments provide at start up.
Please note that all the above 3 types of memory resides in RAM.
No comments:
Post a Comment