All Downloads are FREE. Search and download functionalities are using the official Maven repository.

blah.concurrency.first.Producer Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package blah.concurrency.first;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class Producer {

	final ExecutorService executor = Executors.newCachedThreadPool();
	final BlockingQueue data = new LinkedBlockingQueue();
	final CountDownLatch counter;

	public Consumer createConsumer() {
		final Consumer consumer = new Consumer(data, counter);
		executor.submit(consumer);
		return consumer;
	}

	public void createConsumers( final int amountOfConsumers ) {
		for ( int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy