mx4j/src/core/mx4j/monitor MX4JMonitor.java,1.4,1.5

Simone Bordet <[email protected]> Sun, 15 May 2005 20:20:14 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/mx4j/monitor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27166/src/core/mx4j/monitor

Modified Files:
	MX4JMonitor.java 
Log Message:
Fix for bug #1201848: shut down the monitor thread started by the TimeQueue when all monitors are stopped

Index: MX4JMonitor.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/mx4j/monitor/MX4JMonitor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** MX4JMonitor.java	13 Feb 2005 18:10:21 -0000	1.4
--- MX4JMonitor.java	15 May 2005 20:20:12 -0000	1.5
***************
*** 14,17 ****
--- 14,18 ----
  import java.util.List;
  import java.util.Map;
+ 
  import javax.management.AttributeNotFoundException;
  import javax.management.InstanceNotFoundException;
***************
*** 50,53 ****
--- 51,55 ----
  {
     private static TimeQueue queue = new TimeQueue();
+    private static int references = 0;
     private static int sequenceNumber;
  
***************
*** 59,68 ****
     private volatile long granularity = 10 * 1000; // Spec says default is 10 seconds
     private boolean errorNotified;
- 
-    static
-    {
-       queue.start();
-    }
- 
     private final TimeTask task = new MonitorTask();
     private final Map infos = new HashMap();
--- 61,64 ----
***************
*** 134,138 ****
        for (Iterator i = infos.values().iterator(); i.hasNext();)
        {
!          MonitorInfo info = (MonitorInfo) i.next();
           info.clearNotificationStatus();
        }
--- 130,134 ----
        for (Iterator i = infos.values().iterator(); i.hasNext();)
        {
!          MonitorInfo info = (MonitorInfo)i.next();
           info.clearNotificationStatus();
        }
***************
*** 198,201 ****
--- 194,203 ----
     protected void startMonitor()
     {
+       synchronized (queue)
+       {
+          if (references == 0) queue.start();
+          ++references;
+       }
+ 
        if (emitter == null) this.emitter = createNotificationEmitter();
        queue.schedule(task);
***************
*** 205,208 ****
--- 207,215 ----
     {
        queue.unschedule(task);
+ 
+       synchronized (queue)
+       {
+          if (--references == 0) queue.stop();
+       }
     }
  



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click