liveBook · Manning

Multithreaded program

As explained in Troubleshooting Java: Read, debug, and optimize JVM applications

A multithreaded architecture is a program design in which multiple threads execute concurrently.

A multithreaded program uses multiple threads to carry out work concurrently. Unless instructions are synchronized, independent threads may execute them in different orders. section 5.1.4

Figure 5.8 A multithreaded architecture. An app with the capability to use multiple threads running concurrently to process data is a multithreaded app. Unless explicitly synchronized, instructions running on independent threads (A, B, and C) can run in any order.

The diagram illustrates how independent threads can run concurrently and why their instructions may not follow one fixed order. section 5.1.4

Investigating such programs can be tricky: a debugger or profiler may interfere with execution and change the behavior being observed. Logs are less likely to alter execution. Timestamps help establish operation order, and recording each thread’s name can help identify which thread ran an instruction. section 5.1.4

Record the current thread

In Java, String threadName = Thread.currentThread().getName(); retrieves the executing thread’s name. Threads may have developer-assigned names or JVM-generated names such as Thread-0. section 5.1.4

How Troubleshooting Java: Read, debug, and optimize JVM applications covers it

How deep it goes
Defines concurrent execution and explains interference and log-based tracing, while leaving broader Java concurrency knowledge outside the treatment.
Examples
Uses timestamped logs and Java’s current-thread name to trace which thread executes an instruction.
What it assumes
Assumes basic Java threading knowledge, including thread states and synchronization.
What you can do after
Diagnose execution behavior by ordering log messages and identifying the thread responsible for an instruction.
How it connects
Connects threads with synchronization, logging, debuggers, profilers, and thread states.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java: Read, debug, and optimize JVM applications. The section links point to the parts of the book it draws on.