package ru.job4j.simpleBlockingQueue;

public class ParallelSearch {

    public static void main(String[] args) throws InterruptedException {
        SimpleBlockingQueue<Integer> queue = new SimpleBlockingQueue<Integer>();
        final  boolean blockCunsomer = true;

        final Thread consumer = new Thread(
                () -> {
                    while (true) {
                        try {
                            if (!queue.queue.isEmpty()) {
                                System.out.println(queue.poll());
                            } else {
                                Thread.currentThread().interrupt();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }
                    }
                }
        );
        consumer.start();
        new Thread(
                () -> {
                    for (int index = 0; index != 3; index++) {
                        queue.offer(index);
                        System.out.println(queue.queue.peek());
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

        ).start();
    }
}

@@ -60,16 +60,31 @@
 lSearch 
+extends Thread 
 %7B%0A%0A    p
@@ -277,17 +277,16 @@
 = true;%0A
-%0A
         
@@ -372,20 +372,55 @@
  while (
-true
+!Thread.currentThread().isInterrupted()
 ) %7B%0A    
@@ -535,35 +535,16 @@
         
-System.out.println(
 queue.po
@@ -547,17 +547,16 @@
 e.poll()
-)
 ;%0A      
@@ -781,17 +781,16 @@
 race();%0A
-%0A
         
@@ -799,32 +799,33 @@
               %7D%0A
+%0A
                 
@@ -881,24 +881,25 @@
 er.start();%0A
+%0A
         new 
@@ -1065,47 +1065,13 @@
     
-System.out.println(queue.queue.peek());
+try %7B
 %0A   
@@ -1083,37 +1083,54 @@
                 
-try %7B
+    Thread.sleep(500);
 %0A               
@@ -1142,32 +1142,53 @@
         
-Thread.sleep(500
+System.out.println(queue.queue.poll()
 );%0A     

task #187593