Use volatile to ensure changes to a variable are visible to all threads, crucial for safe publication and visibility in multithreading.
Source Code
volatile boolean running = true;
public void stopRunning() {
running = false; // Writes to 'running' are immediately visible to other threads
}