fundamentals
Thread-specific runtime data areas in JVM and their roles?
Thread-Specific Areas:
- PC (Program Counter) Register: Maintains the address of the current JVM instruction being executed. Each thread has its own PC register.
- JVM Stack: Stores "Stack Frames". A new frame is created for every method call. Contains local variables, operand stack, and frame data.
- Native Method Stack: Used for native methods (written in C/C++).
Impact of Thread Creation:
- Creating a thread allocates memory for these three areas.
- Memory Overhead: Excessive thread creation can lead to
OutOfMemoryError(unable to create new native thread) orStackOverflowErrorif thread stacks are too deep. - Tuning:
-Xsssets the stack size per thread.