Example usage for java.util.concurrent TransferQueue put

List of usage examples for java.util.concurrent TransferQueue put

Introduction

In this page you can find the example usage for java.util.concurrent TransferQueue put.

Prototype

void put(E e) throws InterruptedException;

Source Link

Document

Inserts the specified element into this queue, waiting if necessary for space to become available.

Usage

From source file:TQProducer.java

public static void main(String[] args) {
    final TransferQueue<Integer> tQueue = new LinkedTransferQueue<>();
    final AtomicInteger sequence = new AtomicInteger();

    for (int i = 0; i < 5; i++) {
        try {/*from w w  w. j a v a 2s. c  o  m*/
            tQueue.put(sequence.incrementAndGet());
            System.out.println("Initial queue: " + tQueue);

            new TQProducer("Producer-1", tQueue, sequence).start();
            new TQConsumer("Consumer-1", tQueue).start();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}