As we all know in java, Thread.join(long millis) means "Waits at most millis milliseconds for this thread to die", but i find the millisecond is not very accuracy, please see the following code:
public class MyThreadTest {
public void invokeTest() {
long executionTimeLimit = 10;
Runner rn = new Runner();
rn.start();
try {
long time = System.currentTimeMillis();
rn.join(executionTimeLimit);
long l1 = (System.currentTimeMillis() - time);
System.out.println("execution_time_limit="+executionTimeLimit+" the invoke method time is "+l1+" millisecond");
} catch (Exception e) {
//e.printStackTrace();
}
}
public static void main(String args[]) {
MyThreadTest mtt = new MyThreadTest();
mtt.invokeTest();
}
private final class Runner extends Thread {
public void run()
{
//to make the program a bit longer
int size = 3000;
String[][] bb = new String[size][size];
for(int i=0;i<size;i++)
for(int j=0;j<size;j++) {
bb[i][j] = "bbbbbbbbbbb";
}
}
}
}
the output log is not same when you running more than one times:
"execution_time_limit=10 the invoke method time is 11 millisecond" "execution_time_limit=10 the invoke method time is 32 millisecond" "execution_time_limit=10 the invoke method time is 34 millisecond"
why does that happen?