@@ -66,9 +66,9 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
6666 if (timeout < 0 )
6767 throw new AssertionError ("Timeout cannot be less than zero" );
6868
69- long maxTime = System .currentTimeMillis () + timeout ;
70- long now ;
71- while (!_filled && (now = System .currentTimeMillis ( )) < maxTime ) {
69+ long now = System .nanoTime () / NANOS_IN_MILLI ;
70+ long maxTime = now + timeout ;
71+ while (!_filled && (now = ( System .nanoTime () / NANOS_IN_MILLI )) < maxTime ) {
7272 wait (maxTime - now );
7373 }
7474
@@ -83,12 +83,19 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
8383 * @return the waited-for value
8484 */
8585 public synchronized T uninterruptibleGet () {
86- while (true ) {
87- try {
88- return get ();
89- } catch (InterruptedException ex ) {
90- // no special handling necessary
86+ boolean wasInterrupted = false ;
87+ try {
88+ while (true ) {
89+ try {
90+ return get ();
91+ } catch (InterruptedException ex ) {
92+ // no special handling necessary
93+ wasInterrupted = true ;
94+ }
9195 }
96+ } finally {
97+ if (wasInterrupted )
98+ Thread .currentThread ().interrupt ();
9299 }
93100 }
94101
@@ -104,14 +111,20 @@ public synchronized T uninterruptibleGet() {
104111 public synchronized T uninterruptibleGet (int timeout ) throws TimeoutException {
105112 long now = System .nanoTime () / NANOS_IN_MILLI ;
106113 long runTime = now + timeout ;
107-
108- do {
109- try {
110- return get (runTime - now );
111- } catch (InterruptedException e ) {
112- // Ignore.
113- }
114- } while ((timeout == INFINITY ) || ((now = System .nanoTime () / NANOS_IN_MILLI ) < runTime ));
114+ boolean wasInterrupted = false ;
115+ try {
116+ do {
117+ try {
118+ return get (runTime - now );
119+ } catch (InterruptedException e ) {
120+ // Ignore.
121+ wasInterrupted = true ;
122+ }
123+ } while ((timeout == INFINITY ) || ((now = System .nanoTime () / NANOS_IN_MILLI ) < runTime ));
124+ } finally {
125+ if (wasInterrupted )
126+ Thread .currentThread ().interrupt ();
127+ }
115128
116129 throw new TimeoutException ();
117130 }
0 commit comments