For tracking, I see 100% usage on both cores when I run this code on my dual core. If I give the number of threads from two to one, one core goes to 100%, and the other about 4%.
package test; import java.util.ArrayList; public class ThreadTest { public void startCPUHungryThread() { Runnable runnable = new Runnable(){ public void run() { while(true) { } } }; Thread thread = new Thread(runnable); thread.start(); } public static void main(String[] args) { ThreadTest thread = new ThreadTest(); for (int i=0; i<2; i++) { thread.startCPUHungryThread(); } } }
tilish
source share