There was an error while loading. Please reload this page.
1 parent da8d834 commit 63707feCopy full SHA for 63707fe
thread/Interrupted.java
@@ -0,0 +1,21 @@
1
+public class PrimeProducer extends Thread {
2
+ private final BlockingQueue<BigInteger> queue;
3
+
4
+ PrimeProducer(BlockingQueue<BigInteger> queue) {
5
+ this.queue = queue;
6
+ }
7
8
+ public void run() {
9
+ try {
10
+ BigInteger p = BigInteger.ONE;
11
+ // check 'interrupted' flag
12
+ while (!Thread.currentThread().isInterrupted())
13
+ queue.put(p = p.nextProbablePrime());
14
+ } catch (InterruptedException consumed) {
15
+ /* Allow thread to exit */
16
17
18
19
+ // mark Thread as 'interrupted'
20
+ public void cancel() { interrupt(); }
21
+}
0 commit comments