You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by ra...@apache.org on 2001/03/19 07:16:01 UTC
cvs commit: jakarta-avalon/src/java/org/apache/avalon/util SynchronizedPriorityQueue.java
ramc 01/03/18 22:16:00
Added: src/java/org/apache/avalon/util
SynchronizedPriorityQueue.java
Log:
Thread safe version of PriorityQueue. Provides synchronized wrapper methods for all the methods in the PriorityQueue interface.
Revision Changes Path
1.1 jakarta-avalon/src/java/org/apache/avalon/util/SynchronizedPriorityQueue.java
Index: SynchronizedPriorityQueue.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.util;
import java.util.NoSuchElementException;
/**
* A thread safe version of the PriorityQueue.
* Provides synchronized wrapper methods for all the methods
* defined in the PriorityQueue interface.
*
* @author <a href="mailto:ram.chidambaram@telus.com">Ram Chidambaram</a>
*/
public final class SynchronizedPriorityQueue
implements PriorityQueue
{
protected final PriorityQueue m_priorityQueue;
public SynchronizedPriorityQueue( final PriorityQueue priorityQueue )
{
m_priorityQueue = priorityQueue;
}
/**
* Clear all elements from queue.
*/
public synchronized void clear()
{
m_priorityQueue.clear();
}
/**
* Test if queue is empty.
*
* @return true if queue is empty else false.
*/
public synchronized boolean isEmpty()
{
return m_priorityQueue.isEmpty();
}
/**
* Insert an element into queue.
*
* @param element the element to be inserted
*/
public synchronized void insert( final Comparable element )
{
m_priorityQueue.insert( element );
}
/**
* Return element on top of heap but don't remove it.
*
* @return the element at top of heap
* @exception NoSuchElementException if isEmpty() == true
*/
public synchronized Comparable peek() throws NoSuchElementException
{
return m_priorityQueue.peek();
}
/**
* Return element on top of heap and remove it.
*
* @return the element at top of heap
* @exception NoSuchElementException if isEmpty() == true
*/
public synchronized Comparable pop() throws NoSuchElementException
{
return m_priorityQueue.pop();
}
public String toString()
{
return m_priorityQueue.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: SynchronizedPriorityQueue questions/suggestions
Posted by Peter Donald <do...@apache.org>.
At 01:22 19/3/01 -0800, Harmeet Bedi wrote:
>A few questions/suggestions
>- Would it make sense in the contructor to make a clone of the presmably
>unsynchronized <priorityQueue>. Not doing that would impose the burden of
>corrent use on the user.
I think it is a burden a user can handle as they will mostly do it at the
start. CLoning is generally not neccesary at that time and may not be
possible for all implementations of PriorityQueue.
>- Would it may make sense to sycnhronize the <toString> method. One thread
>might do an insert operation and another may grab a snapshot via toString
>before the <insert> method finishes.
good point - probably would be good ;)
>- Does it make sense to use Doug Lea's util.concurrent package for some of
>multi threading capabilities or build on that package if there is a need. It
>may be a good idea reuse really good libraries if they are avaliable.
>util.concurrent does not seem to have any license hangups and has an
>excellent reputation. The last time I looked at it, there was some Queue
>management facilities
>http://g.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
No idea on the license but they are brilliant libraries (have used em
before). To be honest the only reason I haven't looked at it for
AValon/Phoenix is because most of my servers have simple synchronisation
design ;)
>- Using JDK 1.3 proxies may provide more general purpose wrapping facility.
>Does the avalon/util/ProxyGenerator provide similar facilities ? I don't
>think there is a problem in manually writing a few wrappers, but if there
>are a lot of wrappers written or likely to be written, it may be better to
>generalize that. It could benefit Avalon code and users of Avalon.
JDK1.3 proxies add a fair bit of overhead - they were really designed for
EJB/CORBA/Other Container implementors etc. ProxyGenerator has less
overhead but apparently it has issues on some JVMS (which I have yet to
track down).
A generic wrapper facility could be usful in the future but probably not
required at the moment. At least I don't need it ;)
Cheers,
Pete
*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof." |
| - John Kenneth Galbraith |
*-----------------------------------------------------*
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
SynchronizedPriorityQueue questions/suggestions
Posted by Harmeet Bedi <hb...@yahoo.com>.
A few questions/suggestions
- Would it make sense in the contructor to make a clone of the presmably
unsynchronized <priorityQueue>. Not doing that would impose the burden of
corrent use on the user.
- Would it may make sense to sycnhronize the <toString> method. One thread
might do an insert operation and another may grab a snapshot via toString
before the <insert> method finishes.
- Does it make sense to use Doug Lea's util.concurrent package for some of
multi threading capabilities or build on that package if there is a need. It
may be a good idea reuse really good libraries if they are avaliable.
util.concurrent does not seem to have any license hangups and has an
excellent reputation. The last time I looked at it, there was some Queue
management facilities
http://g.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
- Using JDK 1.3 proxies may provide more general purpose wrapping facility.
Does the avalon/util/ProxyGenerator provide similar facilities ? I don't
think there is a problem in manually writing a few wrappers, but if there
are a lot of wrappers written or likely to be written, it may be better to
generalize that. It could benefit Avalon code and users of Avalon.
Harmeet
----- Original Message -----
From: <ra...@apache.org>
To: <ja...@apache.org>
Sent: Sunday, March 18, 2001 10:16 PM
Subject: cvs commit: jakarta-avalon/src/java/org/apache/avalon/util
SynchronizedPriorityQueue.java
> ramc 01/03/18 22:16:00
>
> Added: src/java/org/apache/avalon/util
> SynchronizedPriorityQueue.java
> Log:
> Thread safe version of PriorityQueue. Provides synchronized wrapper
methods for all the methods in the PriorityQueue interface.
>
> Revision Changes Path
> 1.1
jakarta-avalon/src/java/org/apache/avalon/util/SynchronizedPriorityQueue.jav
a
>
> Index: SynchronizedPriorityQueue.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.avalon.util;
>
> import java.util.NoSuchElementException;
>
> /**
> * A thread safe version of the PriorityQueue.
> * Provides synchronized wrapper methods for all the methods
> * defined in the PriorityQueue interface.
> *
> * @author <a href="mailto:ram.chidambaram@telus.com">Ram
Chidambaram</a>
> */
> public final class SynchronizedPriorityQueue
> implements PriorityQueue
> {
> protected final PriorityQueue m_priorityQueue;
>
> public SynchronizedPriorityQueue( final PriorityQueue
priorityQueue )
> {
> m_priorityQueue = priorityQueue;
> }
>
> /**
> * Clear all elements from queue.
> */
> public synchronized void clear()
> {
> m_priorityQueue.clear();
> }
>
> /**
> * Test if queue is empty.
> *
> * @return true if queue is empty else false.
> */
> public synchronized boolean isEmpty()
> {
> return m_priorityQueue.isEmpty();
> }
>
> /**
> * Insert an element into queue.
> *
> * @param element the element to be inserted
> */
> public synchronized void insert( final Comparable element )
> {
> m_priorityQueue.insert( element );
> }
>
> /**
> * Return element on top of heap but don't remove it.
> *
> * @return the element at top of heap
> * @exception NoSuchElementException if isEmpty() == true
> */
> public synchronized Comparable peek() throws NoSuchElementException
> {
> return m_priorityQueue.peek();
> }
>
> /**
> * Return element on top of heap and remove it.
> *
> * @return the element at top of heap
> * @exception NoSuchElementException if isEmpty() == true
> */
> public synchronized Comparable pop() throws NoSuchElementException
> {
> return m_priorityQueue.pop();
> }
>
> public String toString()
> {
> return m_priorityQueue.toString();
> }
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org