Patch: FYI: Fix for PR 4859

Mark Wielaard mark@klomp.org
Fri Oct 5 14:24:00 GMT 2001


Hi,

On Tue, Nov 13, 2001 at 04:31:55PM -0700, Tom Tromey wrote:
>  
> +    /**
> +     * This method returns <code>true</code> if the queue has been
> +     * stopped.
> +     */
> +    public synchronized boolean isStopped ()
> +    {
> +      return this.heap == null;
> +    }
>    }				// TaskQueue
>  
>    /**
> @@ -337,8 +345,9 @@
>  		}
>  	    }
>  
> -	  // Calculate next time and possibly re-enqueue
> -	  if (task.scheduled >= 0)
> +	  // Calculate next time and possibly re-enqueue.
> +	  // Don't bother re-scheduling if the queue has been stopped.
> +	  if (! queue.isStopped () && task.scheduled >= 0)
>  	    {
>  	      if (task.fixed)
>  		{

This fix still has a (very small) chance of generating the same "bug".
If the timer is stopped between the !queue.isStopperd() and the
queue.enqueue(task) then you will still get the IllegalStateException.

A better fix would be to actually try to reschedule the task and catch
(and ignore) the exception.

2001-11-16  Mark Wielaard  <mark@klomp.org>

        * java/util/Timer.java (TaskQueue.isStopped): Remove method.
        (Scheduler.run): Try to re-schedule task and ignore exception if
        queue has been stopped.

OK to commit?

Cheers,

Mark
-- 
Stuff to read:
    <http://www.toad.com/gnu/whatswrong.html>
  What's Wrong with Copy Protection, by John Gilmore
-------------- next part --------------
Index: java/util/Timer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Timer.java,v
retrieving revision 1.4
diff -u -r1.4 Timer.java
--- Timer.java	2001/11/13 23:09:23	1.4
+++ Timer.java	2001/11/16 16:45:18
@@ -285,14 +285,6 @@
       this.notify();
     }
 
-    /**
-     * This method returns <code>true</code> if the queue has been
-     * stopped.
-     */
-    public synchronized boolean isStopped ()
-    {
-      return this.heap == null;
-    }
   }				// TaskQueue
 
   /**
@@ -346,8 +338,7 @@
 	    }
 
 	  // Calculate next time and possibly re-enqueue.
-	  // Don't bother re-scheduling if the queue has been stopped.
-	  if (! queue.isStopped () && task.scheduled >= 0)
+	  if (task.scheduled >= 0)
 	    {
 	      if (task.fixed)
 		{
@@ -356,8 +347,16 @@
 	      else
 		{
 		  task.scheduled = task.period + System.currentTimeMillis();
+		}
+
+	      try
+	        {
+	          queue.enqueue(task);
+		}
+	      catch (IllegalSteException ise)
+	        {
+		  // Ignore. Apparently the Timer queue has been stopped.
 		}
-	      queue.enqueue(task);
 	    }
 	}
     }


More information about the Java-patches mailing list