You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by de...@avalon.apache.org on 2004/08/15 22:47:20 UTC

[jira] Commented: (RUNTIME-52) SimpleFIFO in Merlin model composition wastes CPU cycles

The following comment has been added to this issue:

     Author: Niclas Hedhman
    Created: Sun, 15 Aug 2004 1:46 PM
       Body:
This way of doing things is 'habit' from the early days of Java.

The time 'wasted' every 100ms is neglectable, and not an issue of concern. I can point at any part of the code and optimize a lot more than that. In the early days, I recall having some problems with not receiving the notify(), and hence always provided 'safety measures'.

notify() vs notifyAll(), is also an early day Java thing, and I don't know the exact difference in behaviour.
It used to be something like; notify() will notify "a thread" whilst notifyAll() would guarantee that no thread was waiting forever. After all, only one thread will at any point in time be allowed inside the synchronized block, so _I_ haven't checked the actually differences nowadays.

Early days refer to mainly JDK 1.0.2.
---------------------------------------------------------------------
View this comment:
  http://issues.apache.org/jira/browse/RUNTIME-52?page=comments#action_37256

---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/RUNTIME-52

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: RUNTIME-52
    Summary: SimpleFIFO in Merlin model composition wastes CPU cycles
       Type: Improvement

     Status: Open
   Priority: Major

    Project: Merlin Runtime
 Components: 
             COMPOSITION
   Versions:
             3.4.0

   Assignee: Stephen McConnell
   Reporter: Carel Paradis

    Created: Sun, 15 Aug 2004 1:28 PM
    Updated: Sun, 15 Aug 2004 1:46 PM

Description:
The class SimpleFifo in the Merlin Model implementation wastes CPU cycles every 100 ms. The method get verify if the queue is no longer empty every 100 ms instead of waiting to be notified when a new element is added to the queue. Also, the put method notifies all waiting threads instead of notifying only one thread. It is not necessary to notify all threads because if many threads are waiting, then only one can get the newly added element.

The following file must be updated: trunk\runtime\composition\impl\src\java\org\apache\avalon\composition\model\impl\SimpleFIFO.java

Apply the following patch:

// -----BEGIN PATCH
Index: SimpleFIFO.java
===================================================================
--- SimpleFIFO.java	(revision 36413)
+++ SimpleFIFO.java	(working copy)
@@ -48,7 +48,7 @@
         synchronized( this )
         {
             m_Queue.add( obj );
-            notifyAll();
+            notify();
         }
     }
     
@@ -58,7 +58,7 @@
         synchronized( this )
         {
             while( m_Queue.size() == 0 )
-                wait(100);
+                wait();
             return m_Queue.remove(0);
         }
     }
// -----END PATCH



---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org