clearing Java\CPU cache programmatically
Solution 1:
This is probably due to the JIT kicking in. The JIT will compile your bytecode to machine code after a certain number of runs to make it more efficient.
You can change the number of calls before a method gets optimised by setting the -XX:CompileThreshold
option (default value is 10,000) or by excluding your class from being optimised at all.
However I'm not sure why you would want to disable the compiler and force your program to run more slowly.