File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -76,13 +76,17 @@ public synchronized T get() throws InterruptedException {
7676 * @throws InterruptedException if this thread is interrupted
7777 */
7878 public synchronized T get (long timeout ) throws InterruptedException , TimeoutException {
79- if (timeout < 0 && timeout != INFINITY )
79+ if (timeout == INFINITY ) return get ();
80+
81+ if (timeout < 0 )
8082 throw new AssertionError ("Timeout cannot be less than zero" );
81-
82- if (!_filled && timeout != 0 ) {
83- wait (timeout == INFINITY ? 0 : timeout );
83+
84+ long maxTime = System .currentTimeMillis () + timeout ;
85+ long now ;
86+ while (!_filled && (now = System .currentTimeMillis ()) < maxTime ) {
87+ wait (maxTime - now );
8488 }
85-
89+
8690 if (!_filled )
8791 throw new TimeoutException ();
8892
You can’t perform that action at this time.
0 commit comments