Java virtual threads, introduced in JDK 19, enhance application performance and memory efficiency. They reduce memory consumption, improve availability and throughput, and mitigate 'OutOfMemoryError' risks. Virtual threads allow for simpler code maintenance by enabling sequential programming. They are fully compatible with existing platform thread APIs, facilitating seamless integration.
APIs to create Java Virtual Thread
Java virtual threads, introduced in JDK 19, enhance application availability, throughput, and code quality while minimizing memory use. This post explains various APIs to create virtual threads, including Thread.startVirtualThread(), Thread.ofVirtual().start(), and Executors. Understanding these features can improve application performance and thread management significantly.
Is Java Virtual Threads lightweight?
Java virtual threads consume significantly less memory compared to platform threads, demonstrated by programs creating 10,000 threads. While virtual thread creation is faster, both types use similar CPU resources and execution times when performing tasks. Adopting virtual threads can enhance memory efficiency and response time in applications with numerous threads or high stack sizes.
Java UUID generation – Performance impact
The 'java.util.UUID#randomUUID()' API in Java uses operating system entropy to generate unique identifiers. A lack of entropy can lead to blocked threads, causing application unresponsiveness. To mitigate this, one can upgrade to RHEL 7, install Haveged for better randomness, or configure Java to use '/dev/urandom' for number generation.
Java threads – may not be memory efficient?
The study reveals that Java threads, regardless of their active or dormant states, consume equivalent memory upon creation. Testing with two programs demonstrated that both empty and full stack frame threads allocated the same memory. Developers are advised to minimize thread creation and optimize stack sizes to reduce memory waste.
Chaos Engineering – Simulating CPU spike
This article explains how to simulate 100% CPU consumption using an infinite loop in multiple threads with Java's BuggyApp application. It details the implementation of the 'CPUSpikeDemo' and 'CPUSpikerThread' classes. The author also suggests methods for diagnosing spikes, including manual thread dumps and automated analysis tools like yCrash for root cause identification.
yCrash Demo video
yCrash app is a secure and non-intrusive tool designed for instant root cause analysis during production issues. It captures various artifacts like thread dumps and GC logs in real-time and promptly analyzes them to generate a comprehensive root cause analysis report on the dashboard. A video overview is available.
