#68710: Solving the starvation in LoaderPoolNode by creating task that is by default finished release551u1_base version-2-3-56
authorjtulach@netbeans.org
Mon, 21 Nov 2005 07:35:51 +0000
changeset 882f9f8798c64d
parent 87 bd6cb339885b
child 89 8520aae0c19d
#68710: Solving the starvation in LoaderPoolNode by creating task that is by default finished
openide.util/apichanges.xml
openide.util/manifest.mf
openide.util/src/org/openide/util/RequestProcessor.java
openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java
     1.1 --- a/openide.util/apichanges.xml	Wed Nov 16 21:44:50 2005 +0000
     1.2 +++ b/openide.util/apichanges.xml	Mon Nov 21 07:35:51 2005 +0000
     1.3 @@ -22,6 +22,22 @@
     1.4      <apidef name="actions">Actions API</apidef>
     1.5  </apidefs>
     1.6  <changes>
     1.7 +    <change id="rp-create-true" >
     1.8 +      <api name="util"/>
     1.9 +      <summary>Ability to create finished RequestProcessor task</summary>
    1.10 +      <version major="6" minor="8"/>
    1.11 +      <date day="22" month="11" year="2005"/>
    1.12 +      <author login="jtulach"/>
    1.13 +      <compatibility addition="yes" modification="no" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no"/>
    1.14 +      <description>
    1.15 +        <a href="@TOP@/org/openide/util/RequestProcessor.html">RequestProcessor.create(Runnable, boolean)</a>
    1.16 +        has been added to allow creation of 
    1.17 +        <a href="@TOP@/org/openide/util/RequestProcessor.Task.html">Task</a>
    1.18 +        that has not executed its runnable yet, but looks like it is finished.
    1.19 +      </description>
    1.20 +      <class package="org.openide.util" name="RequestProcessor"/>
    1.21 +      <issue number="68031"/>
    1.22 +    </change>
    1.23      <change id="less-events-from-proxylookup" >
    1.24        <api name="lookup"/>
    1.25        <summary>Less change notifications from ProxyLookup</summary>
     2.1 --- a/openide.util/manifest.mf	Wed Nov 16 21:44:50 2005 +0000
     2.2 +++ b/openide.util/manifest.mf	Mon Nov 21 07:35:51 2005 +0000
     2.3 @@ -1,5 +1,5 @@
     2.4  Manifest-Version: 1.0
     2.5  OpenIDE-Module: org.openide.util
     2.6 -OpenIDE-Module-Specification-Version: 6.7
     2.7 +OpenIDE-Module-Specification-Version: 6.8
     2.8  OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
     2.9  
     3.1 --- a/openide.util/src/org/openide/util/RequestProcessor.java	Wed Nov 16 21:44:50 2005 +0000
     3.2 +++ b/openide.util/src/org/openide/util/RequestProcessor.java	Mon Nov 21 07:35:51 2005 +0000
     3.3 @@ -243,14 +243,36 @@
     3.4  
     3.5      /** Creates request that can be later started by setting its delay.
     3.6      * The request is not immediatelly put into the queue. It is planned after
     3.7 -    * setting its delay by schedule method.
     3.8 +    * setting its delay by schedule method. By default the initial state of 
     3.9 +    * the task is <code>!isFinished()</code> so doing waitFinished() will
    3.10 +    * block on and wait until the task is scheduled.
    3.11      *
    3.12      * @param run action to run in the process
    3.13      * @return the task to control execution of given action
    3.14      */
    3.15      public Task create(Runnable run) {
    3.16 -        return new Task(run);
    3.17 +        return create(run, false);
    3.18      }
    3.19 +    
    3.20 +    /** Creates request that can be later started by setting its delay.
    3.21 +    * The request is not immediatelly put into the queue. It is planned after
    3.22 +    * setting its delay by schedule method.
    3.23 +    *
    3.24 +    * @param run action to run in the process
    3.25 +    * @param initiallyFinished should the task be marked initially finished? If 
    3.26 +    *   so the {@link waitFinished} on the task will succeeded immediatelly even
    3.27 +    *   the task has not yet been {@link Task.schedule}d.
    3.28 +    * @return the task to control execution of given action
    3.29 +    * @since 6.8
    3.30 +    */
    3.31 +    public Task create(Runnable run, boolean initiallyFinished) {
    3.32 +        Task t = new Task(run);
    3.33 +        if (initiallyFinished) {
    3.34 +            t.notifyFinished();
    3.35 +        }
    3.36 +        return t;
    3.37 +    }
    3.38 +    
    3.39  
    3.40      /** Tests if the current thread is request processor thread.
    3.41      * This method could be used to prevent the deadlocks using
     4.1 --- a/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java	Wed Nov 16 21:44:50 2005 +0000
     4.2 +++ b/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java	Mon Nov 21 07:35:51 2005 +0000
     4.3 @@ -392,26 +392,38 @@
     4.4      /** Check whether task is finished when it should be.
     4.5       */
     4.6      public void testCheckFinished () {
     4.7 +        doCheckFinished(false);
     4.8 +    }
     4.9 +    public void testCheckFinishedWithFalse () {
    4.10 +        doCheckFinished(true);
    4.11 +    }
    4.12 +    
    4.13 +    private void doCheckFinished(boolean usefalse) {
    4.14          RequestProcessor rp = new RequestProcessor ("Finish");
    4.15 -        
    4.16 -        class R extends Object implements Runnable {
    4.17 -            RequestProcessor.Task t;
    4.18 -            
    4.19 -            public void run () {
    4.20 -                if (t.isFinished ()) {
    4.21 -                    fail ("Finished when running");
    4.22 -                }
    4.23 -            }
    4.24 +
    4.25 +class R extends Object implements Runnable {
    4.26 +    RequestProcessor.Task t;
    4.27 +    
    4.28 +    public void run () {
    4.29 +        if (t.isFinished ()) {
    4.30 +            fail ("Finished when running");
    4.31          }
    4.32 +    }
    4.33 +}
    4.34          
    4.35          R r = new R ();
    4.36 -        RequestProcessor.Task task = rp.create (r);
    4.37 +        RequestProcessor.Task task = usefalse ? rp.create(r, false) : rp.create (r);
    4.38          r.t = task;
    4.39  
    4.40          if (task.isFinished ()) {
    4.41              fail ("Finished after creation");
    4.42          }
    4.43       
    4.44 +        doCommonTestWithScheduling(task);
    4.45 +    }
    4.46 +
    4.47 +    private void doCommonTestWithScheduling(final RequestProcessor.Task task) {
    4.48 +     
    4.49          task.schedule (200);
    4.50          
    4.51          if (task.isFinished ()) {
    4.52 @@ -430,6 +442,31 @@
    4.53              fail ("Finished when planed");
    4.54          }
    4.55      }
    4.56 +
    4.57 +    public void testCheckFinishedWithTrue () {
    4.58 +        RequestProcessor rp = new RequestProcessor ("Finish");
    4.59 +        
    4.60 +        class R extends Object implements Runnable {
    4.61 +            RequestProcessor.Task t;
    4.62 +            
    4.63 +            public void run () {
    4.64 +                if (t.isFinished ()) {
    4.65 +                    fail ("Finished when running");
    4.66 +                }
    4.67 +            }
    4.68 +        }
    4.69 +        
    4.70 +        R r = new R ();
    4.71 +        RequestProcessor.Task task = rp.create(r, true);
    4.72 +        r.t = task;
    4.73 +
    4.74 +        assertTrue("It has to be finished after creation", task.isFinished());
    4.75 +
    4.76 +        task.waitFinished();
    4.77 +
    4.78 +        // rest is the same
    4.79 +        doCommonTestWithScheduling(task);
    4.80 +    }
    4.81          
    4.82  
    4.83      /** Test to check the waiting in request processor.