Code example for LinkedBlockingDeque

Methods: sleep

0
package com.sunshine.procon; 
 
import java.util.concurrent.BlockingQueue; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.LinkedBlockingDeque; 
 
public class Main { 
	public static void main(String[] args) throws InterruptedException {
		//建立缓冲区 
		BlockingQueue<PCData> queue = new LinkedBlockingDeque<PCData>();
		Producer p1 = new Producer(queue);
		Producer p2 = new Producer(queue);
		Producer p3 = new Producer(queue);
		Consumer c1 = new Consumer(queue);
		Consumer c2 = new Consumer(queue);
		Consumer c3 = new Consumer(queue);
		ExecutorService es = Executors.newCachedThreadPool();
		es.execute(p1);
		es.execute(p2);
		es.execute(p3);
		es.execute(c1);
		es.execute(c2);
		es.execute(c3);
		 
		Thread.sleep(10 * 1000);
		 
		System.out.println("停止---------------------------------------------");
		p1.stop();
		p1.stop();
		p1.stop();
Stop searching for code, let great code find you!  Add Codota to your java IDE