Wondering what makes Java applications hard to scale up to thousands of concurrent tasks?
The solution is the cost of platform threads, which are the traditional Java threads. In this blog, we will discuss the behavior of platform threads when loaded, limitations, and why developers are moving to the new virtual threads of Java in order to scale.
Java Platform Threads are Costly
Java platform threads are costly because of:
- OS-level memory
- Context switching
- Lifecycle costs
Java platform threads are heavyweight operating system threads, which:
- Use a lot of memory (usually 1MB stack memory)
- Are costly to create and operate at large scale
The JVM throws errors like:
OutOfMemoryError: unable to create new native thread
What are Platform Threads in Java?
Java has a traditional thread supported by a native operating system thread called a platform thread.
Each thread:
- Is created with new Thread API
- Takes dedicated stack memory (1MB by default)
- Is restricted by OS thread limits