I'm debug(Shift + F9) the method offer(E e)
of JDK8 API's java.util.concurrent.ConcurrentLinkedQueue
,
i found IntelliJ IDEA will change the field head
of this queue soundlessly in the process of debugging,
but the run schema(Shift + F10) will not change the field, why?
and there's no code change this field in offer(E e)
, it makes me confused.
Then, I tried another IDE(Eclipse Mars.1 Release (4.5.1)), it hasn't such problem.
There are some result of my test:
- run schema (Shift + F10)
head: 1159190947
head: 1159190947
head: 1159190947
head: 1159190947
- debug schema (Step over: F8)
head: 1989972246
head: 1791930789
head: 1791930789
head: 1791930789
- debug schema (Resume program: F9)
head: 1989972246
head: 1989972246
head: 1791930789
head: 1791930789
version info :
IntelliJ IDEA 2018.1 (Ultimate Edition)
Build #IU-181.4203.550, built on March 27, 2018
JRE: 1.8.0_162-b12 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
And IntelliJ IDEA 2018.2.3 (Community Edition) & IntelliJ IDEA 2019.1 (Ultimate Edition) has the same problem.
import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ConcurrentLinkedQueueTest {
public static void main(String[] args) {
ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
print(queue);
queue.offer("aaa");
print(queue);
queue.offer("bbb");
print(queue);
queue.offer("ccc");
print(queue);
}
/**
* 打印并发队列head属性的identityHashCode
* @param queue
*/
private static void print(ConcurrentLinkedQueue queue) {
Field field = null;
boolean isAccessible = false;
try {
field = ConcurrentLinkedQueue.class.getDeclaredField("head");
isAccessible = field.isAccessible();
if (!isAccessible) {
field.setAccessible(true);
}
System.out.println("head: " + System.identityHashCode(field.get(queue)));
} catch (Exception e) {
e.printStackTrace();
} finally {
field.setAccessible(isAccessible);
}
}
}