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 {
76
76
* @throws InterruptedException if this thread is interrupted
77
77
*/
78
78
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 )
80
82
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 );
84
88
}
85
-
89
+
86
90
if (!_filled )
87
91
throw new TimeoutException ();
88
92
You can’t perform that action at this time.
0 commit comments