• Post Reply Bookmark Topic Watch Topic
  • New Topic

Consumer and Producer Problem  RSS feed

 
gail belfast
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Im writing a program based on the consumer producer problem. It works in that the required number of producers enter and exit. However the program is required to have the producers exit a random times The spec given says that the exit time should be generated based on entrance time and a random stay time and i really cant figure out a way to do this so any help would be appreciated. I have included the code i am using for the producer and consumer classes.





 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gail belfast wrote:Im writing a program based on the consumer producer problem. It works in that the required number of producers enter and exit. However the program is required to have the producers exit a random times The spec given says that the exit time should be generated based on entrance time and a random stay time and i really cant figure out a way to do this so any help would be appreciated. I have included the code i am using for the producer and consumer classes.

This is probably going to sound like something you've seen before, but StopCoding (←click).

Queuing is NOT simple, so you can't just simply solve it by bashing out code.

Write down WHAT you want to happen, not HOW you want to do it. And write it in English (or your native language) so that when you actually code your program, you can be sure it follows your instructions.

Some questions:
Consumer enters. What do you want to happen?
Producer enters. Ditto.
What does a Producer do?
When do you want to notify your Consumer(s)?

You need to be able to answer all these question in English; otherwise you haven't solved the problem. And you will NEVER code a Java program to do so until you have (well possibly, but it'll be by pure chance).

HIH. And welcome to the Ranch.

Winston

 
gail belfast
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the answers to the questions you asked appear in the buffer monitor and test buffer code that I didn't post . I do know what i want my program to do it just that my class have only started multi-treading two weeks ago and as i have little experience with java i find is hard to do what i would consider to be the more advanced stuff .

Thanks for your advice !!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gail belfast wrote:All the answers to the questions you asked appear in the buffer monitor and test buffer code that I didn't post . I do know what i want my program to do it just that my class have only started multi-treading two weeks ago and as i have little experience with java i find is hard to do what i would consider to be the more advanced stuff .

OK, so probably even more good reason to stop, back up, and write things down.

It's a common problem with beginners, so don't worry about it; but you expect code to solve your problem ('God, if only I knew how to do THIS').

Well it doesn't help. Take it from an old soldier (37 years and counting). It's possible it might solve your problem today, but not not the one that comes up tomorrow. And if you want to be good, THAT'S what you need to learn.

So (and it may not be what you want to hear): Stop. Turn your computer off. Sharpen a pencil. Get out your notes from before (if you have them) and lots of paper.
And THINK.
Write down scenarios, Draw diagrams. Think about when things might NOT work right.

Programming is not easy, Gail, and (especially with a problem like this) you need to be using your brain, not your fingers.

I have no doubt that someone could tell you the line or lines of code that are wrong in your program, but you won't learn much. And I suspect if you can describe to us what you want your program to do, you may well work out the solution for yourself.

Best of luck.

Winston
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!