how to implement producer consumer problem with multiple producers and multiple consumers?? how should we create threads?? Give me some overall idea..
Thanks in advance
how to implement producer consumer problem with multiple producers and multiple consumers?? how should we create threads?? Give me some overall idea..
Thanks in advance
Create a producer and a consumer class both of which are extending Thread class, and call them whenever you need. Where did you get stuck?
Perhaps you should make use of goole more :-)
Try This article and this source code for more info.
Sun has a Concurrency tutorial that covers essential threading classes. There's information on Defining and Starting a Thread that should answer your how to create a thread question nicely.
ConcurrentQueue q = new ConcurrentQueue(100);
ExecutorService service = Executors.newFixedThreadPool(20);
service.execute(new Producer(q));
for (int i=0; i < 18; i++) {
service.execute(new Consumer(q));
}
Where both Consumer
and Producer
are custom classes that extend Runnable and take a Queue
as their constructor argument.