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
