Possible Duplicate:
Would a multithreaded Java application exploit a multi-core machine very well?
I have a plain and simple Java thread like this running on my dual-core machine (Windows XP 32bit enviroment)
public static void main(String[] strs) {
long j = 0;
for(long i = 0; i<Long.MAX_VALUE; i++)
j++;
System.out.println(j);
}
My expectation was that it would stick to a single CPU to fully exploit the high-speed cache(since in the loop we keep operating with local variable j, hence one CPU utiliaztion would be 100% and the other would be pretty much idle. To my suprise both of the CPUs are being utilized at around 40%~60% after the thread starts and the utilization of one CPU is slightly higher than the other.
My question is that Is there any OS load-balancing mechanism that kicks in when out-of-balance has been detected? In my case is it possible that Windows OS found that one CPU is hitting nearly 100% and the other is almost idle so it reschedules the thread to another CPU periodically?
#EDIT1 I've found a possible explanation: http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node130.html