Your explanation is right.
The compiler detects than stopReq
is never modified in the loop and since it is not volatile
, optimizes the while(!stopReq)
instruction to while(true)
.
Even though the value changes later, the thread does not even read it any more.
More Related Contents:
- How to wait for all threads to finish, using ExecutorService?
- Is there an advantage to use a Synchronized Method instead of a Synchronized Block?
- Why is creating a Thread said to be expensive?
- When and how should I use a ThreadLocal variable?
- What is the difference between Thread.start() and Thread.run()?
- Java Wait and Notify: IllegalMonitorStateException
- Are static variables shared between threads?
- How do synchronized static methods work in Java and can I use it for loading Hibernate entities?
- Is iterating ConcurrentHashMap values thread safe?
- Why use a ReentrantLock if one can use synchronized(this)?
- Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?
- How do I implement task prioritization using an ExecutorService in Java 5?
- Constructor synchronization in Java
- More efficient way for pausing loop wanted
- Javafx: Difference between javafx.concurent and Platform.runLater?
- Instruction reordering & happens-before relationship [duplicate]
- Programmatic deadlock detection in java
- When should we use Java’s Thread over Executor?
- Why does java.util.concurrent.ArrayBlockingQueue use ‘while’ loops instead of ‘if’ around calls to await()?
- Run Java Threads sequentially
- WAITING at sun.misc.Unsafe.park(Native Method)
- ThreadPoolExecutor Block When its Queue Is Full?
- Java : Does wait() release lock from synchronized block
- How Threadpool re-use Threads and how it works
- Concurrent JUnit testing
- Handling Exceptions for ThreadPoolExecutor
- LinkedBlockingQueue vs ConcurrentLinkedQueue
- Setting Ideal size of Thread Pool [duplicate]
- Does a breakpoint halt all threads?
- ExecutorCompletionService? Why do need one if we have invokeAll?