@@ -66,9 +66,9 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
66
66
if (timeout < 0 )
67
67
throw new AssertionError ("Timeout cannot be less than zero" );
68
68
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 ) {
72
72
wait (maxTime - now );
73
73
}
74
74
@@ -83,12 +83,19 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
83
83
* @return the waited-for value
84
84
*/
85
85
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
+ }
91
95
}
96
+ } finally {
97
+ if (wasInterrupted )
98
+ Thread .currentThread ().interrupt ();
92
99
}
93
100
}
94
101
@@ -104,14 +111,20 @@ public synchronized T uninterruptibleGet() {
104
111
public synchronized T uninterruptibleGet (int timeout ) throws TimeoutException {
105
112
long now = System .nanoTime () / NANOS_IN_MILLI ;
106
113
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
+ }
115
128
116
129
throw new TimeoutException ();
117
130
}
0 commit comments