First i would like to clear it that My question is different from the question How to check if the JIT compiler is off in Java which wants jo turn off JIT optimization. I want JIT to run but i want cpu-intensive task to be written in such a way that JIT can not optimize it anyway. Now i start explaining my problem. Following is a CPU-Bound task that is run by a Thread. I am sending this task to my server where a worker from thread pool picks it and runs it. I want workers to run this task at some fixed amount of time but as discussed in my first and second questions at stack-overflow , JIT interferes and optimizes code and as a result workers runs for arbitrary times. I don't want workers to run for different times. I want workers to run for fixed amount of time. What type of codes i should write in following class that cant not be optimized by JIT anyway. please help as this is part of my final year project.Working example would be highly appreciated!
import java.math.BigInteger;
public class CpuBoundJob implements Runnable {
public void run() {
BigInteger factValue = BigInteger.ONE;
long t1=System.nanoTime();
for ( int i = 2; i <= 800; i++){
factValue = factValue.multiply(BigInteger.valueOf(i));
}
long t2=System.nanoTime();
System.out.println("Service Time(ms)="+((double)(t2-t1)/1000000));
}
}