User: ejort   
  Date: 02/04/14 08:22:38

  Modified:    src/main/javax/management/monitor Monitor.java
  Log:
  A monitor service that doesn't busy wait
  
  Revision  Changes    Path
  1.5       +45 -48    jmx/src/main/javax/management/monitor/Monitor.java
  
  Index: Monitor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/javax/management/monitor/Monitor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Monitor.java      24 Mar 2002 13:12:12 -0000      1.4
  +++ Monitor.java      14 Apr 2002 15:22:37 -0000      1.5
  @@ -33,7 +33,7 @@
    * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public abstract class Monitor
     extends NotificationBroadcasterSupport
  @@ -147,7 +147,7 @@
      */
     static void add(Monitor monitor)
     {
  -    monitors.add(monitor.monitorRunnable);
  +     monitors.add(monitor.monitorRunnable);
     }
   
     /**
  @@ -155,7 +155,7 @@
      */
     static void remove(Monitor monitor)
     {
  -    monitors.remove(monitor.monitorRunnable);
  +     monitors.remove(monitor.monitorRunnable);
     }
   
     /**
  @@ -164,16 +164,13 @@
     static void reschedule()
     {
       // Loop through the monitors to find the next run.
  -    synchronized (monitors)
  +    nextRunDate = 0;
  +    Iterator iterator = monitors.iterator();
  +    while (iterator.hasNext())
       {
  -      nextRunDate = 0;
  -      Iterator iterator = monitors.iterator();
  -      while (iterator.hasNext())
  -      {
  -        MonitorRunnable runnable = (MonitorRunnable) iterator.next();
  -        if (runnable.running == false)
  -           runnable.reschedule(false);
  -      }
  +       MonitorRunnable runnable = (MonitorRunnable) iterator.next();
  +       if (runnable.running == false)
  +          runnable.reschedule(false);
       }
     }
     
  @@ -507,15 +504,15 @@
        */
       void reschedule(boolean notify)
       {
  -      synchronized (this)
  -      {
  -        if (nextRunDate == 0 || nextDate < nextRunDate)
  -        {
  -          nextRunDate = nextDate;
  -          if (notify == true)
  -            controller.interrupt();
  -        }
  -      }
  +       synchronized(monitors)
  +       {
  +          if (nextRunDate == 0 || nextDate < nextRunDate)
  +          {
  +             nextRunDate = nextDate;
  +             if (notify == true)
  +               monitors.notify();
  +          }
  +       }
       }
   
       // Runnable overrides -------------------------------------------
  @@ -582,37 +579,37 @@
         {
           synchronized (monitors)
           {
  -          Iterator iterator = monitors.iterator();
  -          while (iterator.hasNext())
  -          {
  -            MonitorRunnable runnable = (MonitorRunnable) iterator.next();
  -
  -            // Run required?
  -            if (runnable.running == false 
  -                && runnable.nextDate <= System.currentTimeMillis())
  -            {
  -              runnable.running = true;
  -              threadPool.run(runnable);
  -            }
  +           Iterator iterator = monitors.iterator();
  +           while (iterator.hasNext())
  +           {
  +             MonitorRunnable runnable = (MonitorRunnable) iterator.next();
  + 
  +             // Run required?
  +             if (runnable.running == false 
  +                 && runnable.nextDate <= System.currentTimeMillis())
  +             {
  +                runnable.running = true;
  +                threadPool.run(runnable);
  +             }
             }
  -        }
   
  -        // Reschedule the waiting monitors
  -        reschedule();
  +          // Reschedule the waiting monitors
  +          reschedule();
   
  -        // Wait until the next monitor required or we are interrupted
  -        try
  -        {
  -          if (nextRunDate == 0)
  -            sleep(0);
  -          else
  -          {
  -            long waitMillis = nextRunDate - System.currentTimeMillis();
  -            if (waitMillis > 0)
  -              sleep(waitMillis);
  -          }
  +           // Wait until the next monitor required or we are interrupted
  +           try
  +           {
  +              if (nextRunDate == 0)
  +                 monitors.wait(999999);
  +              else
  +              {
  +                 long waitMillis = nextRunDate - System.currentTimeMillis();
  +                 if (waitMillis > 0)
  +                    monitors.wait(waitMillis);
  +              }
  +           }
  +           catch (InterruptedException ignored) {}
           }
  -        catch (InterruptedException ignored) {}
         }
       }
     }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to