try some thing like this:
float ALOUD_MISTAKE = 20; // percent
int WORK_TIME = 1000; // milliseconds
public int work(){
int workCounter = 0;
long startTime = System. currentTime();
long currentTime = System. currentTime();
while(startTime < currentTime + WORK_TIME){
currentTime = System. currentTime();
workCounter++;
}
return workCounter;
}
start mainThread1;
check the work time and save it(keep it going)
now start new thread
new Thread(new Runnable(){
void run(){
while(true){
work();
}
}
}).start();
let them run a bit and now check:
if(Math.abs(workTimeThread1 - savedWorkTimeThread1) / workTimeThread1 * 100 > ALOUD_MISTAKE)
{
you got (number of new threads been started - 1) cores
}