time_to_wait-= (System.currentTimeMillis() - start_time);
time_to_wait=timeout - (System.currentTimeMillis() - start_time);
    public void waitUntilEmpty(long timeout) throws QueueClosedException, TimeoutException {        long time_to_wait=timeout >=0? timeout : 0; // eliminate negative values        try {            mutex.acquire();            if(timeout == 0) {                while(size > 0 && closed == false) {                    remove_condvar.await();                }            }            else {                long start_time=System.currentTimeMillis();                while(time_to_wait > 0 && size > 0 && closed == false) {                    try {                        remove_condvar.timedwait(time_to_wait);                    }                    catch(InterruptedException ex) {                    }                    time_to_wait-= (System.currentTimeMillis() - start_time);                }                if(size > 0)                    throw new TimeoutException("queue has " + size + " elements");            }            if(closed)                throw new QueueClosedException();        }        catch(InterruptedException e) {        }        finally {            mutex.release();        }    }