File tree 2 files changed +6
-4
lines changed
src/main/java/br/com/leonardoz
2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,8 @@ public static void usingBlockingQueue() {
155
155
156
156
} catch (InterruptedException e ) {
157
157
// interrupted pattern
158
+ // InterruptedException makes isInterrupted returns false
159
+ Thread .currentThread ().interrupt ();
158
160
System .err .println ("Consumer Finished" );
159
161
}
160
162
}
@@ -181,7 +183,7 @@ public static void usingBlockingQueue() {
181
183
}
182
184
};
183
185
184
- // Multiple producers - Examples using simple threads this time.
186
+ // Multiple producers - Examples using simple threads this time.
185
187
Thread producer1 = new Thread (runProducer );
186
188
producer1 .start ();
187
189
Thread producer2 = new Thread (runProducer );
@@ -204,8 +206,8 @@ public static void usingBlockingQueue() {
204
206
}
205
207
206
208
public static void main (String [] args ) {
207
- usingConcurrentHashMap ();
208
- usingCopyOnWriteArrayList ();
209
+ // usingConcurrentHashMap();
210
+ // usingCopyOnWriteArrayList();
209
211
usingBlockingQueue ();
210
212
}
211
213
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public class ThreadTaskCancel {
19
19
private Thread thread ;
20
20
private Runnable task = () -> {
21
21
while (!Thread .currentThread ().isInterrupted ()) {
22
- // keep going
22
+ // keep going - be aware of using this Pattern with the Interrupted exception! It won't work.
23
23
}
24
24
};
25
25
You can’t perform that action at this time.
0 commit comments