views:

851

answers:

4

Hello, for a programming assignment I have been asked to implement a solution to the Dining Philosopher problem. I must do so in two ways:

  1. Use the wait() and notifyAll() mechanism
  2. Using an existing concurrent data structure provided in the Java API

I have already complete the first implementation. Which concurrent data structure is my professor talking about for step two? I don't remember her mentioning anything. I don't need any source code, just a pointer in the right direction.

A: 

Perhaps she meant wrapping Java collections in synchronized wrappers, e.g. using Collections.synchronizedList(), or the always synchronized data structures in java.util.concurrent, e.g. CopyOnWriteArrayList.

Fabian Steeg
+2  A: 

You might want to look at the java.util.concurrent Javadoc page to get some ideas. These are not the only concurrent data structures (some of the java.util data structures also have built-in concurrency support) but this is a good starting point.

Collections.synchronizedList is not what I would call "an existing concurrent data structure" -- it is a wrapper for data structures that do not support concurrency.

jdigital
Yes, the `java.util.concurrent.ConcurrentMap` interface has several interesting methods in it that would allow you to implement a solution.
Bill Michell
A: 

Not really a data structure... but in the neighborhood of what you might need http://java.sun.com/javase/6/docs/api/java/util/concurrent/Semaphore.html?

TofuBeer
If you're heading that direction, then java.util.concurrent.locks.Lock has some interesting methods. tryLock() in particular looks appropriate.
Bill Michell
A: 

There is a concurrent library in the Java API.

It has some collections

Look at the java.util.concurrent package

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html

Bill K