• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Concurrent Programming

 
Floetic Angel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey There,

I�m looking for advice on how to tackle a problem.

The problem is I want to create a simulation of a restaurant scenario using java to code it.

I need to specify the concurrent processes, the sequential activities carried out by each actor and the constructs used to provide mutual exclusion and condition synchronisation.


At the moment this is how I�m thinking of going about tackling it:

�Have one table say with a maximum of 8 seats.

�The actors are the waiter, the customers and reception.

�I need to figure out what each actor should be doing.

�There should be a time limit of some sort for how long customers can be at a table perhaps?

�Some functions/procedures could be wait(), eat(), talk(), order()

�Write classes for the Customer, Waiter, Reception (Booking, Checking In) and Table.

�All classes have to talk to each other in order to run a successful Restaurant simulation.


Am I looking at the problem in the right way or are there other alternative approaches using java that would be better, in trying to simulate this scenario?

Thank You In Advance For Any Advice That Is Offered!

~ Floetic ~
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Underground Passion,

Unfortunately your screen name does not follow the naming policy that we follow here at javaranch. Request you to kindly change the same. (The link has all the information as to how to change it)

Coming to your question:
(I liked the way you have described the problem)
Basically, what you have written down is nothing related to Java as a language. You are trying to figure out the entities in your system and their interaction, such an exercise is done best using a modelling language like UML. So, your question that "Am I looking at the problem in the right way or are there other alternative approaches using java that would be better" does not really make much sense.

(IMHO this topic can be moved to an appropriate forum)

Ofcourse, the entities you have listed are good (i would like to add one more entity, kitchen, this will definetly have a lot of effect on how much time a client have to wait for food after order and you can simulate the high rush scenarios in a restaurent) but you need to come up with the scenarios of how the entities communicate with each other and more granular methods on each entity.
If you do the above, you will be in a position to tell what is the data that each entity maintain and what all interactions will change the data. Once you get this information, you will be in a good shape to decide the synchronization strategies for the entities and the data they store.

I hope this helps.

[ February 27, 2008: Message edited by: Nitesh Kant ]
[ February 27, 2008: Message edited by: Nitesh Kant ]
 
Floetic Angel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much for the suggestions and I will take that all into consideration but I want to learn how to do that using Java...
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure exactly where this question belongs but I wanted to address

All classes have to talk to each other in order to run a successful Restaurant simulation.


The is definitely not the right direction to head. Nitesh already mentioned a Kitchen entity. Do you suppose the Customer, Reception, many other classes have any direct interaction with the Kitchen?

When I order something from a Waiter - I tell the waiter what I want. Your code should work the same. The Customer entity should not have to know about the kitchen (or cook(s)) to order() a dish.

Perhaps I'm just picking on the grammar a bit - but it is a very important point - IMHO.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carla Pinate:
Thank You very much for the suggestions and I will take that all into consideration but I want to learn how to do that using Java...


Hi Carla, (Thanks for changing the screen name.)
What have you tried till now. Can you post some code?
What exactly you were not able to get related to Java while implementing the above.
Conceptually, the interaction between most of the entities should be asynchronous i.e. each entity working for the restaurant will have a work queue (except for between a customer and a waiter). All entities will finish their work and put the result into another work queue (eg: a waiter will put the order into the work queue of a chef, a chef will execute and put the order back into the queue of the waiter. Waiter will deliver and then will put the bill in the queue of the cashier and so on)
To implement a work queue you can look at ThreadPoolExecutor and related classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!