Book Image

Java: High-Performance Apps with Java 9

By : Mayur Ramgir
Book Image

Java: High-Performance Apps with Java 9

By: Mayur Ramgir

Overview of this book

Java 9 which is one of the most popular application development languages. The latest released version Java 9 comes with a host of new features and new APIs with lots of ready to use components to build efficient and scalable applications. Streams, parallel and asynchronous processing, multithreading, JSON support, reactive programming, and microservices comprise the hallmark of modern programming and are now fully integrated into the JDK. This book focuses on providing quick, practical solutions to enhance your application's performance. You will explore the new features, APIs, and various tools added in Java 9 that help to speed up the development process. You will learn about jshell, Ahead-of-Time (AOT) compilation, and the basic threads related topics including sizing and synchronization. You will also explore various strategies for building microservices including container-less, self-contained, and in-container. This book is ideal for developers who would like to build reliable and high-performance applications with Java. This book is embedded with useful assessments that will help you revise the concepts you have learned in this book. This book is repurposed for this specific learning experience from material from Packt's Java 9 High Performance by Mayur Ramgir and Nick Samoylov
Table of Contents (9 chapters)
Java: High-Performance Apps with Java 9
Credits
Preface

Sizing Thread Pool Executors


In our examples, we have used a cached thread pool that creates a new thread as needed or, if available, reuses the thread already used, but which completed its job and returned to the pool for a new assignment. We did not worry about too many threads created because our demo application had two worker threads at the most and they were quite short lived.

But in the case where an application does not have a fixed limit of the worker threads it might need or there is no good way to predict how much memory a thread may take or how long it can execute, setting a ceiling on the worker thread count prevents an unexpected degradation of the application performance, running out of memory or depletion of any other resources the worker threads use. If the thread behavior is extremely unpredictable, a single thread pool might be the only solution, with an option of using a custom thread pool executor (more about this last option is explained later). But in most of the cases...