time_to_wait-=System.currentTimeMillis()-start;
time_to_wait=timeout - (System.currentTimeMillis() - start);
    private Object _getResultWithTimeout(long timeout) throws TimeoutException {        Object  ret=null;        long    time_to_wait=timeout, start;        boolean timeout_occurred=false;        start=System.currentTimeMillis();        while(hasResult == false) {            if(timeout <= 0) {                doWait();            }            else {                if(time_to_wait <= 0) {                    timeout_occurred=true;                    break; // terminate the while loop                }                else {                    doWait(time_to_wait);                    time_to_wait-=System.currentTimeMillis()-start;                }            }        }        ret=result;        result=null;        hasResult=false;        if(timeout_occurred)            throw new TimeoutException();        else            return ret;    }