@@ -0,0 +1,3080 @@
+package ru.szhernovoy.template;%0A%0Aimport java.util.concurrent.ArrayBlockingQueue;%0Aimport java.util.concurrent.BlockingQueue;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0A/**%0A * Created by szhernovoy on 26.10.2016.%0A */%0Apublic class ProducerCustomer %7B%0A%0A    private AtomicInteger num = new AtomicInteger(0);%0A    private final BlockingQueue%3CAtomicInteger%3E queue = new ArrayBlockingQueue%3C%3E(5);%0A%0A    public int getNum() %7B%0A        return num.get();%0A    %7D%0A%0A    public void add()%7B%0A        synchronized (this.queue)%7B%0A            System.out.println(String.format(%22work Producer %25s - add num %25d%22,Thread.currentThread().getId(),this.num.get()));%0A            try %7B%0A                this.queue.put(this.num);%0A                this.num.getAndIncrement();%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A            this.queue.notify();%0A        %7D%0A%0A    %7D%0A%0A    public void getData()  %7B%0A         synchronized (this.queue)%7B%0A            while(this.queue.isEmpty())%7B%0A                try %7B%0A                    System.out.println(String.format(%22wait Customer %25s%22,Thread.currentThread().getId()));%0A                    this.queue.wait();%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A%0A             try %7B%0A                 System.out.println(String.format(%22wait Customer %25s - get num %25d%22,Thread.currentThread().getId(),this.queue.take().get()));%0A             %7D catch (InterruptedException e) %7B%0A                 e.printStackTrace();%0A             %7D%0A%0A         %7D%0A%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final ProducerCustomer info = new ProducerCustomer();%0A        Thread producer = new Thread()%7B%0A            /**%0A             * If this thread was constructed using a separate%0A             * %3Ccode%3ERunnable%3C/code%3E run object, then that%0A             * %3Ccode%3ERunnable%3C/code%3E object's %3Ccode%3Erun%3C/code%3E method is called;%0A             * otherwise, this method does nothing and returns.%0A             * %3Cp%3E%0A             * Subclasses of %3Ccode%3EThread%3C/code%3E should override this method.%0A             *%0A             * @see #start()%0A             * @see #stop()%0A             * @see #(ThreadGroup, Runnable, String)%0A             */%0A            @Override%0A            public void run() %7B%0A                info.add();%0A            %7D%0A        %7D;%0A%0A        Thread customer = new Thread()%7B%0A            /**%0A             * If this thread was constructed using a separate%0A             * %3Ccode%3ERunnable%3C/code%3E run object, then that%0A             * %3Ccode%3ERunnable%3C/code%3E object's %3Ccode%3Erun%3C/code%3E method is called;%0A             * otherwise, this method does nothing and returns.%0A             * %3Cp%3E%0A             * Subclasses of %3Ccode%3EThread%3C/code%3E should override this method.%0A             *%0A             * @see #start()%0A             * @see #stop()%0A             * @see #(ThreadGroup, Runnable, String)%0A             */%0A            @Override%0A            public void run() %7B%0A                info.getData();%0A            %7D%0A        %7D;%0A        customer.start();%0A        producer.start();%0A%0A%0A    %7D%0A%7D%0A

update lesson 4 block queue