Java – mention and reorder the same thing?
Read from effective Java. Without synchronization, the following sequence a can be converted to sequence B by the virtual machine, which is called promotion I also read somewhere that volatile instructions can be reordered if variables are not declared as involving variables Rise and rearrange the same thing?
while (!done) sequence A i++; if (!done) while (true) sequence B i++;
Solution
They are slightly different
Promotion means that you have pulled some operations out of the loop, because the loop itself does not affect the result of the operation In your case, you are promoting the conditional test from the while loop
Reordering means changing the sequence of instructions in a way that does not affect the result Usually, this will be an adjacent instruction without data correlation. For example, the order in which the following two statements are executed does not matter:
int a = x; int b = y;