Effectively reading and understanding existing code is a developer’s superpower. In this book, you’ll master techniques for code profiling, advanced debugging, and log evaluation to find and fix bugs and performance problems.
In Troubleshooting Java: Read, debug, and optimize JVM applications you will learn how to:
• Determine what code does the first time you see it
• Expose code logic problems
• Evaluate heap dumps to find memory leaks
• Monitor CPU consumption to optimize execution
• Use thread dumps to find and solve deadlocks
• Easily follow a service-oriented or microservices system
• Properly use logging to better understand Java app execution
• Use Java debuggers efficiently
Searching for bugs, detangling messy legacy code, or evaluating your codebase for new features sucks up much of a developer's time. Troubleshooting Java: Read, debug, and optimize JVM applications teaches code investigation techniques that will help you efficiently understand how Java apps work, how to optimize them, and how to fix the bugs that break them. You’ll go from the basics of debugging to advanced methods for locating problems in microservices architectures, and save yourself hours—or even days—of time. Each new technique is explained with lively illustrations and engaging real-world examples.
About the technology
Fact: Over the course of your career, you’ll spend far more time reading code than you will writing it. The code investigation skills in this book will radically improve your efficiency in understanding and improving Java applications.
About the book
Troubleshooting Java: Read, debug, and optimize JVM applications presents practical techniques for exploring and repairing unfamiliar code. In it, you’ll learn timesaving practices for discovering hidden dependencies, discovering the root causes of crashes, and interpreting unexpected results. Go beyond profiling and debugging and start understanding how Java applications really work.
What's inside
• Determine what code does the first time you see it
• Evaluate heap dumps to find memory leaks
• Monitor CPU consumption to optimize execution
• Use thread dumps to find and solve deadlocks
• Uncover glitches in code logic
• Locate intermittent runtime problems
About the reader
For intermediate Java developers.
About the author
Laurențiu Spilcă is a skilled Java and Spring developer and an experienced technology instructor. He is the author of Spring Start Here and Spring Security in Action.
Author(s): Laurentiu Spilca
Edition: 1
Publisher: Manning Publications
Year: 2023
Language: English
Commentary: Publisher's PDF
Pages: 365
City: Shelter Island, NY
Tags: Debugging; Multithreading; Log Data Analysis; Java; SQL; Logging; Memory Management; Profiling; Troubleshooting; Application Development; JVM
Troubleshooting Java
contents
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A roadmap
About the code
liveBook discussion forum
Author online
about the author
about the cover illustration
Part 1: The basics of investigating a codebase
Chapter 1: Revealing an app’s obscurities
1.1 How to more easily understand your app
1.2 Typical scenarios for using investigation techniques
1.2.1 Demystifying the unexpected output
1.2.2 Learning certain technologies
1.2.3 Clarifying slowness
1.2.4 Understanding app crashes
1.3 What you will learn in this book
Chapter 2: Understanding your app’s logic through debugging techniques
2.1 When analyzing code is not enough
2.2 Investigating code with a debugger
2.2.1 What is the execution stack trace, and how do I use it?
2.2.2 Navigating code with the debugger
2.3 When using the debugger might not be enough
Chapter 3: Finding problem root causes using advanced debugging techniques
3.1 Minimizing investigation time with conditional breakpoints
3.2 Using breakpoints that don’t pause the execution
3.3 Dynamically altering the investigation scenario
3.4 Rewinding the investigation case
Chapter 4: Debugging apps remotely
4.1 What is remote debugging?
4.2 Investigating in remote environments
4.2.1 The scenario
4.2.2 Finding issues in remote environments
Chapter 5: Making the most of logs: Auditing an app’s behavior
5.1 Investigating issues with logs
5.1.1 Using logs to identify exceptions
5.1.2 Using exception stack traces to identify what calls a method
5.1.3 Measuring time spent to execute a given instruction
5.1.4 Investigating issues in multithreaded architectures
5.2 Implementing logging
5.2.1 Persisting logs
5.2.2 Defining logging levels and using logging frameworks
5.2.3 Problems caused by logging and how to avoid them
5.3 Logs vs. remote debugging
Part 2: Deep analysis of an app’s execution
Chapter 6: Identifying resource consumption problems using profiling techniques
6.1 Where would a profiler be useful?
6.1.1 Identifying abnormal usage of resources
6.1.2 Finding out what code executes
6.1.3 Identifying slowness in an app’s execution
6.2 Using a profiler
6.2.1 Installing and configuring VisualVM
6.2.2 Observing the CPU and memory usage
6.2.3 Identifying memory leaks
Chapter 7: Finding hidden issues using profiling techniques
7.1 Sampling to observe executing code
7.2 Profiling to learn how many times a method executed
7.3 Using a profiler to identify SQL queries an app executes
7.3.1 Using a profiler to retrieve SQL queries not generated by a framework
7.3.2 Using the profiler to get the SQL queries generated by a framework
7.3.3 Using the profiler to get programmatically generated SQL queries
Chapter 8: Using advanced visualization tools for profiled data
8.1 Detecting problems with JDBC connections
8.2 Understanding the app’s code design using call graphs
8.3 Using flame graphs to spot performance problems
8.4 Analyzing queries on NoSQL databases
Chapter 9: Investigating locks in multithreaded architectures
9.1 Monitoring threads for locks
9.2 Analyzing thread locks
9.3 Analyzing waiting threads
Chapter 10: Investigating deadlocks with thread dumps
10.1 Getting a thread dump
10.1.1 Getting a thread dump using a profiler
10.1.2 Generating a thread dump from the command line
10.2 Reading thread dumps
10.2.1 Reading plain-text thread dumps
10.2.2 Using tools to better grasp thread dumps
Chapter 11: Finding memory- related issues in an app’s execution
11.1 Sampling and profiling for memory issues
11.2 Using heap dumps to find memory leaks
11.2.1 Obtaining a heap dump
11.2.2 Reading a heap dump
11.2.3 Using the OQL console to query a heap dump
Part 3: Finding problems in large systems
Chapter 12: Investigating apps’ behaviors in large systems
12.1 Investigating communication between services
12.1.1 Using HTTP server probes to observe HTTP requests
12.1.2 Using HTTP client probes to observe HTTP requests the app sends
12.1.3 Investigating low-level events on sockets
12.2 The relevance of integrated log monitoring
12.3 Using deployment tools in investigations
12.3.1 Using fault injection to mimic hard-to-replicate issues
12.3.2 Using mirroring to facilitate testing and error detection
appendix A: Tools you’ll need
appendix B: Opening a project
appendix C: Recommended further reading
appendix D: Understanding Java threads
D.1 What is a thread?
D.2 A thread’s life cycle
D.3 Synchronizing threads
D.3.1 Synchronized blocks
D.3.2 Using wait(), notify(), and notifyAll()
D.3.3 Joining threads
D.3.4 Blocking threads for a defined time
D.3.5 Synchronizing threads with blocking objects
D.4 Common issues in multithreaded architectures
D.4.1 Race conditions
D.4.2 Deadlocks
D.4.3 Livelocks
D.4.4 Starvation
D.5 Further reading
appendix E: Memory management in Java apps
E.1 How the JVM organizes an app’s memory
E.2 The stack used by threads to store local data
E.3 The heap the app uses to store object instances
E.4 The metaspace memory location for storing data types
index
A
B
C
D
E
F
G
H
I
J
L
M
N
O
P
Q
R
S
T
U
V
W
X
Z