Concurrent processing - 6 threads sharing resources - wait() and notify()
I am writing a program based on the dining philosophers problem using just wait() and notify() and, as I have never done concurrent processing before, I want to make sure that I am heading in the right direction with what I am doing.
If you don't know, the dining philosophers problem states that there are 6 people around a table with 6 pieces of cutlery in between them (1 to the left and 1 to the right of each person). Two people cannot use the same piece at the same time and both pieces are required for the person to eat. I have to ensure that each person gets a chance to eat (has both pieces at the same time) and each person gets a chance to think (has none). We can't have a person going too long without a piece as they will starve.
Back to my program:
Do I need to make pairs of the people either side of a piece of cutlery, then as one person picks up this piece, the wait() method is called on the other thread (person) to halt it until the other person has finished eating where he will then call notify() to wake up the other thread and let that person pick up the cutlery?
I haven't done any concurrent processing, as I said, so don't know how I link these two threads together. I have seen some mention of "synchronise" on tutorials I have attempted, is that what I need. Also, I am struggling to see a way of doing this for 6 threads (people) simultaneously (Do I just do lots of overlapping synchronisation pairs?).
Can somebody point me in the right direction on how to start or on some good tutorials (Not the orcale one, I have gone through this) that will be helpful for this situation?
Re: Concurrent processing - 6 threads sharing resources - wait() and notify()
If you use "wait notify tutorial" as a search term in google/bing, you'll find loads of relevant pages, e.g.,
There are also YouTube tutorials on this, e.g., Advanced Java: Multi-threading Part 8 - Wait and Notify - YouTube