long base = System.currentTimeMills();
long now = 0;
if(millis < 0){
throw new IllegalArgumentException("timeout value is negative");
}
if(millis == 0){
while(isAlive()){
wait(0);
}
}else{
while(isAlive()){
long delay = millis-now;
if(delay <= 0){
break;
}
wait(delay);
now = System.currentTimeMillis()-base;
}
}