Is it possible for the reordering of statements inside a synchronized block ? For example
synchronized(lock) {
statement1;
statement2;
}
In which, statement1 and statement2 are not dependent on each other. Can the processor or compiler reorder these statements ?
Thank you.
Yes these statements can be reordered within
synchronizedblock if optimizer decides so. But they can’t be taken out ofsynchronized.