---- Peter Donald <[EMAIL PROTECTED]> wrote:
> At 11:25  16/3/01 -0800, Ram C wrote:
> >---- Peter Donald <[EMAIL PROTECTED]> wrote:
> >> At 11:26  15/3/01 -0800, Ram C wrote:
> >> >Should the methods, pop(), insert(),peek() in BinaryHeap be syncronized
> >> >? 
> >> 
> >> Possibly - though I would prefer if they were unsynchronized by
> default
> >> but
> >> you could make them synchronized like
> >> 
> >> PriorityQueue pq = new SynchronizedPriorityQueue( new BinaryHeap()
> >> );
> >
> >I can create a new SynchronizedPriorityQueue(or should it be
> SyncronizedBinaryHeap
> >???) which implements PriorityQueue, and calls all the BinaryHeap
> methods
> >using syncronized wrapper methods.
> 
> I think SynchronizedPriorityQueue because if/when I actually implement
> another type of priority queue this will still work (then again that
> particular job has been on TODO list for at least a year 8-]).

agreed :-),

> 
> >> or perhaps
> >> 
> >> PriorityQueue pq = AvalonCollections.synchronize( new BinaryHeap()
> >> );
> >> 
> >
> >I don't understand this...How would this synchronization work? I can
> >see you want to create a static method 'synchronize' in AvalonCollections.
> >sorry i'm new to these kind of stuff...so please pardon my ignorance.
> 
> Its basically a pattern introduced in Java2 collections. ie You can
> go
> 
> List list = Collections.synchronizedList( new LinkedList() );
> Map map = Collections.synchronizedMap( new HashMap() );
> 
> Which just synchronizes all the methods (presumably by a wrapper like
> described above).

---------------------------------------------------------------------
Collections Javadoc.
---------------------
It is imperative that the user manually synchronize on the returned list
when iterating over it: 

  List list = Collections.synchronizedList(new ArrayList());
      ...
  synchronized(list) {
      Iterator i = list.iterator(); // Must be in synchronized block
      while (i.hasNext())
          foo(i.next());
  }
 
Failure to follow this advice may result in non-deterministic behavior.

------------------------------------------------------------------------

I looks like if i use method 2, i would need synchronized blocks in all
the places i'm using the priority queue.

I prefer method 1(unless you see other benifits with going with method
2), and will proceed and create a SyncronizedPriorityQueue.

Another dumb question...
isFull() in BinaryHeap, though used only within BinaryHeap, is defined
public, in that case should that be defined in the PriorityQueue interface?

Also, the 'percolate' methods should be used only from within the BinaryHeap
(after the insert and pop). Should they be really defined 'private' rather
than 'protected'.  I see a lot of other places where the methods should
be really 'private' but defined 'protected'. Any reasoning for that?

Thanks for all your help.

Cheers,
Ram.

___________________________________________________________
FREE voicemail, email and fax, all in one place.  Sign Up Now! http://www.mybc.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to