@@ -0,0 +1,1822 @@
+package ru.job4j.simpleBlockingQueue;%0A%0Aimport javax.annotation.concurrent.GuardedBy;%0Aimport javax.annotation.concurrent.ThreadSafe;%0Aimport java.util.ArrayDeque;%0Aimport java.util.LinkedList;%0Aimport java.util.Queue;%0A%0A@ThreadSafe%0Apublic class SimpleBlockingQueue %7B%0A%0A    private final Object lock = new Object();%0A%0A    @GuardedBy(%22this%22)%0A    private Queue%3CInteger%3E queue = new LinkedList%3C%3E();%0A%0A    //%D0%92%D1%81%D1%82%D0%B0%D0%B2%D0%BB%D1%8F%D0%B5%D1%82 %D1%8D%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82 %D0%B2 %D0%BA%D0%BE%D0%BD%D0%B5%D1%86 %D0%BE%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D0%B8%0A    public void offer(int value) %7B%0A        queue.offer(value);%0A    %7D%0A%0A    // %D0%B2%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%89%D0%B0%D0%B5%D1%82 %D0%B8 %D1%83%D0%B4%D0%B0%D0%BB%D1%8F%D0%B5%D1%82 %D0%B3%D0%BE%D0%BB%D0%BE%D0%B2%D0%BD%D0%BE%D0%B9 %D1%8D%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82%0A    public int poll() %7B%0A        return queue.poll();%0A    %7D%0A%0A    public void doSomething() throws InterruptedException %7B%0A        synchronized (this.lock) %7B%0A            if (queue.peek()==null) %7B%0A                offer(0);%0A                lock.wait();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void changeBlock() %7B%0A        synchronized (this.lock) %7B%0A            if (queue.peek()!=null) %7B%0A                poll();%0A            %7D%0A            lock.notify();%0A        %7D%0A    %7D%0A%0A    public static void main (String%5B%5D args) throws InterruptedException %7B%0A%0A        // producer %D0%B1%D0%BB%D0%BE%D0%BA%D0%B8%D1%80%D1%83%D0%B5%D1%82 %D0%B5%D1%81%D0%BB%D0%B8 %D0%BE%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D1%8C %D0%B7%D0%B0%D0%BF%D0%BE%D0%BB%D0%BD%D0%B5%D0%BD%D0%B0%0A        // %D0%B4%D0%BE %D1%82%D0%B5%D1%85 %D0%BF%D0%BE%D1%80 %D0%BF%D0%BE%D0%BA%D0%B0 Cunsomer %D0%BD%D0%B5 %D0%B8%D0%B7%D0%B2%D0%BB%D0%B5%D1%87%D0%B5%D1%82 %D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D0%B5 %D0%B8%D0%B7 %D0%BE%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D0%B8%D1%8B%0A        final SimpleBlockingQueue sbq = new SimpleBlockingQueue();%0A%0A        //customer%0A        Thread cunsomer =  new Thread() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    sbq.doSomething();%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D;%0A%0A        //producer%0A        Thread producer = new Thread() %7B%0A            @Override%0A            public void run() %7B%0A                sbq.changeBlock();%0A            %7D%0A        %7D;%0A%0A        cunsomer.start();%0A        producer.start();%0A%0A    %7D%0A%0A%7D%0A

task #187595