// Path: src/main/java/com/bigchange/concurrent/blockingqueue/consumer/Consumer.java
// public class Consumer implements Runnable {
//     BlockingQueue<String> queue; 
//     public Consumer(BlockingQueue<String> queue){  
//         this.queue = queue;  
//     }        
//     @Override  
//     public void run() {  
//         try {  
//         	System.out.println(Thread.currentThread().getName());  
//             String temp = queue.take(); //如果队列为空，会阻塞当前线程
//             System.out.println(temp);  
//         } catch (InterruptedException e) {  
//             e.printStackTrace();  
//         }  
//     }  
// }  
// 
// Path: src/main/java/com/bigchange/concurrent/blockingqueue/producer/Producer.java
// public class Producer implements Runnable {  
//     BlockingQueue<String> queue;    
//     public Producer(BlockingQueue<String> queue) {  
//         this.queue = queue;  
//     }    
//     @Override  
//     public void run() {  
//         try {  
//             
//             System.out.println("I have made a product:"  
//                     + Thread.currentThread().getName()); 
//             String temp = "A Product, 生产线程："  
//                     + Thread.currentThread().getName();  
//             queue.put(temp);//如果队列是满的话，会阻塞当前线程  
//         } catch (InterruptedException e) {  
//             e.printStackTrace();  
//         }  
//     }    
// }  


import com.bigchange.concurrent.blockingqueue.consumer.Consumer;
import com.bigchange.concurrent.blockingqueue.producer.Producer;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
package com.bigchange.concurrent.blockingqueue.main;



public class Test {

	public static void main(String[] args) throws Exception {

		BlockingQueue<String> queue = new LinkedBlockingQueue<String>(2);
		// BlockingQueue<String> queue = new LinkedBlockingQueue<String>();
		// 不设置的话，LinkedBlockingQueue默认大小为Integer.MAX_VALUE
		// BlockingQueue<String> queue = new ArrayBlockingQueue<String>(2);
		Consumer consumer = new Consumer(queue);
		Producer producer = new Producer(queue);
		for (int i = 0; i < 3; i++) {
			new Thread(producer, "Producer" + (i + 1)).start();
		}
		for (int i = 0; i < 5; i++) {
// Path: src/main/java/com/bigchange/concurrent/blockingqueue/consumer/Consumer.java
// public class Consumer implements Runnable {
//     BlockingQueue<String> queue; 
//     public Consumer(BlockingQueue<String> queue){  
//         this.queue = queue;  
//     }        
//     @Override  
//     public void run() {  
//         try {  
//         	System.out.println(Thread.currentThread().getName());  
//             String temp = queue.take(); //如果队列为空，会阻塞当前线程
//             System.out.println(temp);  
//         } catch (InterruptedException e) {  
//             e.printStackTrace();  
//         }  
//     }  
// }  
// 
// Path: src/main/java/com/bigchange/concurrent/blockingqueue/producer/Producer.java
// public class Producer implements Runnable {  
//     BlockingQueue<String> queue;    
//     public Producer(BlockingQueue<String> queue) {  
//         this.queue = queue;  
//     }    
//     @Override  
//     public void run() {  
//         try {  
//             
//             System.out.println("I have made a product:"  
//                     + Thread.currentThread().getName()); 
//             String temp = "A Product, 生产线程："  
//                     + Thread.currentThread().getName();  
//             queue.put(temp);//如果队列是满的话，会阻塞当前线程  
//         } catch (InterruptedException e) {  
//             e.printStackTrace();  
//         }  
//     }    
// }  


// Path: src/main/java/com/bigchange/concurrent/blockingqueue/main/Test.java
import com.bigchange.concurrent.blockingqueue.consumer.Consumer;
import com.bigchange.concurrent.blockingqueue.producer.Producer;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

package com.bigchange.concurrent.blockingqueue.main;



public class Test {

	public static void main(String[] args) throws Exception {

		BlockingQueue<String> queue = new LinkedBlockingQueue<String>(2);
		// BlockingQueue<String> queue = new LinkedBlockingQueue<String>();
		// 不设置的话，LinkedBlockingQueue默认大小为Integer.MAX_VALUE
		// BlockingQueue<String> queue = new ArrayBlockingQueue<String>(2);
		Consumer consumer = new Consumer(queue);
		Producer producer = new Producer(queue);
		for (int i = 0; i < 3; i++) {
			new Thread(producer, "Producer" + (i + 1)).start();
		}
		for (int i = 0; i < 5; i++) {
			new Thread(consumer, "Consumer" + (i + 1)).start();