⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primeproducer.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import java.math.BigInteger;import java.util.concurrent.*;/** * PrimeProducer * <p/> * Using interruption for cancellation * * @author Brian Goetz and Tim Peierls */public class PrimeProducer extends Thread {    private final BlockingQueue<BigInteger> queue;    PrimeProducer(BlockingQueue<BigInteger> queue) {        this.queue = queue;    }    public void run() {        try {            BigInteger p = BigInteger.ONE;            while (!Thread.currentThread().isInterrupted())                queue.put(p = p.nextProbablePrime());        } catch (InterruptedException consumed) {            /* Allow thread to exit */        }    }    public void cancel() {        interrupt();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -