生产者消费者模式用队列实现,如何改写为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计320个文字,预计阅读时间需要2分钟。
javapublic class Consumer implements Runnable { private final BlockingQueue sharedQueue;
public Consumer(BlockingQueue sharedQueue) { this.sharedQueue=sharedQueue; }
public void run() { while (true) { try { sharedQueue.take(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }}
Consumer.javapublic class Consumer implements Runnable { private final BlockingQueue sharedQueue; public Consumer(BlockingQueue sharedQueue) { this.sharedQueue = sharedQueue; } public void run() { while (true) { try { sharedQueue.take(); } catch (InterruptedException e) { e.printStackTrace(); } } } } ProductStorage.java
public class ProductStorage {
private static BlockingQueue
Producter.java
public class Producter implements Runnable {
private final BlockingQueue
public class Test {
public static void main(String[] args) {
ProductStorage.startProductThread();
ProductStorage.startConsumThread();
}
}
本文共计320个文字,预计阅读时间需要2分钟。
javapublic class Consumer implements Runnable { private final BlockingQueue sharedQueue;
public Consumer(BlockingQueue sharedQueue) { this.sharedQueue=sharedQueue; }
public void run() { while (true) { try { sharedQueue.take(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }}
Consumer.javapublic class Consumer implements Runnable { private final BlockingQueue sharedQueue; public Consumer(BlockingQueue sharedQueue) { this.sharedQueue = sharedQueue; } public void run() { while (true) { try { sharedQueue.take(); } catch (InterruptedException e) { e.printStackTrace(); } } } } ProductStorage.java
public class ProductStorage {
private static BlockingQueue
Producter.java
public class Producter implements Runnable {
private final BlockingQueue
public class Test {
public static void main(String[] args) {
ProductStorage.startProductThread();
ProductStorage.startConsumThread();
}
}

