Consider a single producer and 10 consumers as threads. The consumers has to subscribe (Ad themselves) to the producer in-order to get any messages that produces sends.

The expected functionality is that, the producer should add a message to a data structure/collection (you choose of your choice) every 2 minutes and notify all consumers. When the consumers receives a notification, it consumes the message, write the details to a common file.

Message format in that file should be ,

[Consumer Name][<<date and Time it consumes the message>>][Message][Message length]

When you are sure that all the consumers consumed the new message, the message has to be removed from the data structure.

The program should redirect the log messages (util logging) to a log file (say prod-consumer.log) too other than the common file where you write details and log the following actions

    When procedure sends a message and notify all consumers
    Consumer consumed the message
    Number of consumers consumed the new  message
    When message is removed from the data structure/collection

Please note that you will have to handle parallel updates (by consumers) to the same file and also provide good error handling part in-case of any issues. Ensure that you log errors to the log file

Read our rules (which you agreed to when signing up), especially: "Do provide evidence of having done some work yourself if posting questions from school or work assignments"

Comments
i have done alot of work on this problem, but don't know how to do parallel computing.

Show what you have done. This is a common CS problem and whether you want the consumers in the same process, other processes on the same host, or other processes on other hosts, will change how you deal with the problem. There are tools to do this, such as MPI and various distributed messaging tools such as RabbitMQ, AMQP (which Rabbit is based on), Kafka, etc. that will provide publish/subscribe message bus tools for distributed systems. They also work well on a single host. You need to do your research. Don't just expect us to "solve" your problem for you. If you describe more precisely what your environment is and what you need to accomplish, then we can provide some advice. That said, DO NOT expect us to do your job / assignment for you!

FYI, I have been doing this stuff for 35 years, including writing distributed message bus tools that are used in major commercial manufacturing software systems.

Hey Rubberman.. I don't know about these tools. I am simply doing this que using eclipse. my main concern is producer have to notify all the consumers but if i use synchronized block here than all the consumer will have to wait for aquiring the lock. How to over come from this problem. I know thjis is not the way top post the whole que and ask for help but i am new to IT and I don't know the proper approch for asking help. So. don't mind. I'll take care of my mistake.
Thanks for leting me know.

this example is just for sipmle Producer consumer Problem. How would each consumer consume the same message without synchronization? How would Producer notify all consumers??

Sorry, yes, it's designed for normal producer/consumer stuff. You don't often see the need to consume the same event in ten consumers.

But Please read the statement above , every consumer have to consume the same message produse by the producer. When it consumed by all the 10 thrtead then it has to removed from data collection or Queue. There will be parallel consumption of that Produced message.

Edited 10 Months Ago by Sandeep_16

Yes, I want. Producer is not dependent on consumer anyway. It should produce message after every 2 mintus rather the message is consume or not by all the 10 thread but should remove after consumed by last thread.

So you could have a producer thread adding messages and starting a cleanup thread for each message. The cleanup threads could use a countdown latch.

This article has been dead for over six months. Start a new discussion instead.