time_to_wait-=System.currentTimeMillis()-start;
time_to_wait=timeout - (System.currentTimeMillis() - start);
    private void _waitUntilWithTimeout(Object result, long timeout) throws TimeoutException {        long    time_to_wait=timeout, start;        boolean timeout_occurred=false;        synchronized(lock) {            if(result == null && cond == null) return;            start=System.currentTimeMillis();            while(match(result, cond) == 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;                    }                }            }            if(timeout_occurred)                throw new TimeoutException();        }    }