Java 9 High Performance

Book description

Best practices to adapt and bottlenecks to avoid

About This Book

  • Tackle all kinds of performance-related issues and streamline your development
  • Master the new features and new APIs of Java 9 to implement highly efficient and reliable codes
  • Gain an in-depth knowledge of Java application performance and obtain best results from performance testing

Who This Book Is For

This book is for Java developers who would like to build reliable and high-performance applications. Prior Java programming knowledge is assumed.

What You Will Learn

  • Work with JIT compilers
  • Understand the usage of profiling tools
  • Generate JSON with code examples
  • Leverage the command-line tools to speed up application development
  • Build microservices in Java 9
  • Explore the use of APIs to improve application code
  • Speed up your application with reactive programming and concurrency

In Detail

Finally, a book that focuses on the practicalities rather than theory of Java application performance tuning. This book will be your one-stop guide to optimize the performance of your Java applications.

We will begin by understanding the new features and APIs of Java 9. You will then be taught the practicalities of Java application performance tuning, how to make the best use of garbage collector, and find out how to optimize code with microbenchmarking. Moving ahead, you will be introduced to multithreading and learning about concurrent programming with Java 9 to build highly concurrent and efficient applications. You will learn how to fine tune your Java code for best results. You will discover techniques on how to benchmark performance and reduce various bottlenecks in your applications. We'll also cover best practices of Java programming that will help you improve the quality of your codebase.

By the end of the book, you will be armed with the knowledge to build and deploy efficient, scalable, and concurrent applications in Java.

Style and approach

This step-by-step guide provides real-world examples to give you a hands-on experience.

Table of contents

  1. Learning Java 9 Underlying Performance Improvements
    1. Introducing the new features of Java 9
    2. Modular development and its impact
      1. Quick introduction to modules
    3. String operations performance
      1. Compact string
        1. The world of heap
          1. Why bother compressing strings?
          2. What did they do?
          3. What is the escape route?
          4. What is the performance gain?
      2. Indify String Concatenation
        1. Invokedynamic
    4. Storing interned strings in CDS archives
    5. Concurrency performance
    6. Compiler improvements
      1. Tiered Attribution
      2. Ahead-of-Time compilation
    7. Security manager improvements
    8. Graphics rasterizers
    9. Summary
  2. Identifying Performance Bottlenecks
    1. CPU infrastructure
    2. Memory utilization
      1. Java heap
      2. Java stack
      3. Java heap versus stack memory
      4. Escape analysis
      5. Common memory problems
        1. OutOfMemory
          1. Mismanagement of object life cycle: java.lang.OutOfMemoryError: Java heap space
          2. java.lang.OutOfMemoryError: GC Overhead limit exceeded
          3. java.lang.OutOfMemoryError: Permgen space
          4. java.lang.OutOfMemoryError: Metaspace
          5. java.lang.OutOfMemoryError: Unable to create new native thread
          6. java.lang.OutOfMemoryError: request size bytes for reason
          7. java.lang.OutOfMemoryError: Requested array size exceeds VM limit
          8. Out of memory: kill process or sacrifice child
        2. StackOverFlow
    3. Database operations
    4. I/O operations
    5. Network operations
      1. WebSocket Client API
    6. Summary
  3. Learning How to Troubleshoot Code
    1. Measuring performance
    2. Performance checklist
    3. Basic principles of troubleshooting
      1. Why some developers find troubleshooting difficult?
      2. Setting up the environment for troubleshooting
    4. Importance of error handling
      1. A basic try-catch-finally block and its usages
        1. What are try-catch-finally blocks?
        2. Usage of try-catch-finally blocks
      2. Mistakes programmers make when using error handling
      3. Why swallowing exception is bad?
      4. Use of logging
        1. Logging vs Debugging
        2. What are the main components?
        3. How to do logging?
        4. What logging frameworks are available?
          1. Java Util Logging
          2. Log4j 2
          3. Logback
          4. Performance
          5. Support
          6. Ease of Use
        5. Best use case for logging
    5. Analyzing thread dump
      1. What is a thread dump?
        1. Benefits of thread dump analysis
      2. How to collect a thread dump
      3. How to analyze a thread dump
        1. Best practices
    6. Analyzing heap dump
      1. What is a heap dump
        1. Benefits of analyzing heap dumps
      2. When do you analyze a heap dump
      3. How to collect heap dump
      4. How to analyze heap dump
        1. Best practices
    7. Summary
  4. Learning How to Use Profiling Tools
    1. Introducing profiling
    2. Why a developer should use a profiling tool
    3. The art of profiling
      1. Profiling areas
        1. CPU profiling
        2. Memory profiling
        3. Thread profiling
    4. The different types of Java profiling tool
      1. Jmap
      2. VisualVM
      3. JProfiler
      4. XRebel
      5. YourKit
      6. JRockit
      7. BTrace
      8. AQtime
        1. Reporting issues
    5. Summary
  5. Understanding Garbage Collection and Making Use of It
    1. Understanding the Java 9 garbage collector for top optimization
      1. Garbage Collection
      2. The principle of GC
      3. Benefits and demerits of garbage collection
      4. Unpredictability
      5. GC methods
        1. Escape analysis
        2. Reference counting
          1. Space reduction
          2. Cycles
          3. Atomic tasks
    2. GC in Java
      1. Understanding the current Parallel GC
        1. Generations
        2. Heap sizing
    3. Parallelism
      1. Why parallelism?
    4. The new G1 collector
      1. A brief history
      2. Impact on programming
      3. Deep insight on G1GC
      4. Comparing G1 collector to ParallelGC
        1. Common points
        2. The qualities of ParallelGC
        3. The qualities of G1GC
        4. Concurrent mode failures
          1. Understanding memory errors
    5. Summary
  6. Optimizing Code with Microbenchmarking
    1. The concept of microbenchmarking
      1. Microbenchmarks in Java
    2. Understanding the JMH
      1. Setting up the JMH
      2. Building up in the JMH
      3. Benchmark modes in the JMH
        1. Throughput measure
        2. Time-based measures
      4. Applying the JMH in Java projects
        1. What is Maven?
    3. Why use microbenchmarking?
      1. The challenges associated with microbenchmarks
      2. Wrong solutions from microbenchmarks
        1. Wrong component use
        2. Wrong hierarchy
        3. Wrong memory use
        4. Use of a specific environment
    4. The benefits of using the JMH
      1. Understanding the limitations of the JMH
    5. Summary
  7. Speeding Up JSON Generation
    1. A transparent understanding of JSON in Java
    2. A brief history of JSON and examples
    3. Understanding JSON generation
      1. What is Javax.json?
        1. JSON object model
        2. JSON stream
          1. What are events?
          2. How does an event work?
        3. Types in JSON for object modeling
        4. Types in JSON for streaming API
        5. JSON trees
    4. Understanding the tree model
    5. Converting CSV to JSON
    6. Converting Excel to JSON
    7. Understanding value trees
    8. The benefits of using JSON
    9. Summary
  8. Tools for Higher Productivity and Faster Application
    1. The JShell tool usage
      1. Creating a JShell session and setting context
      2. JShell commands
    2. Ahead-of-Time (AOT)
      1. Static versus dynamic compilation
      2. The AOT commands and procedures
    3. Summary
  9. Multithreading and Reactive Programming
    1. Prerequisites
    2. Thread pools
    3. Monitoring threads
    4. Sizing thread pool executors
    5. Thread synchronization
    6. Tuning JVM
    7. Reactive programming
    8. Summary
  10. Microservices
    1. Why microservices?
    2. Building microservices
    3. Container-less deployment
    4. Self-contained microservices
    5. In-container deployment
    6. Summary
  11. Making Use of New APIs to Improve Your Code
    1. Filtering streams
      1. Basic filtering
      2. Using other stream operations for filtering
    2. Stack-walking APIs
      1. Stack analysis before Java 9
      2. New better way to walk the stack
    3. Convenience factory methods for collections
      1. Why new factory methods?
      2. The new factory methods in action
    4. CompletableFuture in support of asynchronous processing
      1. The CompletableFuture API overview
      2. The CompletableFuture API enhancements in Java 9
      3. The problem and the solution using Future
      4. The solution with CompletableFuture
      5. Other useful features of CompletableFuture
    5. Stream API improvements
    6. Summary

Product information

  • Title: Java 9 High Performance
  • Author(s): Mayur Ramgir, Nick Samoylov
  • Release date: November 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787120785