[jboss-cvs] JBossAS SVN: r89151 - in trunk/varia/src/main/org/jboss: monitor/services and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 19 23:07:20 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-05-19 23:07:19 -0400 (Tue, 19 May 2009)
New Revision: 89151

Modified:
   trunk/varia/src/main/org/jboss/monitor/JBossMonitor.java
   trunk/varia/src/main/org/jboss/monitor/SnapshotRecordingMonitor.java
   trunk/varia/src/main/org/jboss/monitor/services/MemoryMonitor.java
   trunk/varia/src/main/org/jboss/monitor/services/ScriptingListener.java
   trunk/varia/src/main/org/jboss/varia/process/ChildProcessService.java
Log:
JBAS-6956 - wrong interrupt handling

Modified: trunk/varia/src/main/org/jboss/monitor/JBossMonitor.java
===================================================================
--- trunk/varia/src/main/org/jboss/monitor/JBossMonitor.java	2009-05-20 03:03:17 UTC (rev 89150)
+++ trunk/varia/src/main/org/jboss/monitor/JBossMonitor.java	2009-05-20 03:07:19 UTC (rev 89151)
@@ -210,27 +210,36 @@
 
    public void run()
    {
-      while (this.getState() == STARTED || this.getState() == STARTING)
+      boolean intr = false;
+      try
       {
-         if (enabled)
+         while (this.getState() == STARTED || this.getState() == STARTING)
          {
+            if (enabled)
+            {
+               try
+               {
+                  testThreshold();
+               }
+               catch (Exception ex)
+               {
+                  log.error(monitorName + " had error while monitoring", ex);
+               }
+            }
             try
             {
-               testThreshold();
+               Thread.sleep(period);
             }
-            catch (Exception ex)
+            catch (InterruptedException ignored)
             {
-               log.error(monitorName + " had error while monitoring", ex);
+               intr = true;
             }
          }
-         try
-         {
-            Thread.sleep(period);
-         }
-         catch (InterruptedException ignored)
-         {
-         }
       }
+      finally
+      {
+         if (intr) Thread.currentThread().interrupt();
+      }
    }
 
    public String getThreshold()

Modified: trunk/varia/src/main/org/jboss/monitor/SnapshotRecordingMonitor.java
===================================================================
--- trunk/varia/src/main/org/jboss/monitor/SnapshotRecordingMonitor.java	2009-05-20 03:03:17 UTC (rev 89150)
+++ trunk/varia/src/main/org/jboss/monitor/SnapshotRecordingMonitor.java	2009-05-20 03:07:19 UTC (rev 89151)
@@ -151,30 +151,39 @@
 
    public void run()
    {
-      startTime = System.currentTimeMillis();
-      while (recording)
+      boolean intr = false;
+      try
       {
-         try
+         startTime = System.currentTimeMillis();
+         while (recording)
          {
-            Object value = mbeanServer.getAttribute(observedObject, attribute);
-            history.add(value);
-            endTime = System.currentTimeMillis();
-         }
-         catch (Exception ex)
-         {
-            log.error(monitorName + " had error while monitoring", ex);
-         }
-         if (recording)
-         {
             try
             {
-               Thread.sleep(period);
+               Object value = mbeanServer.getAttribute(observedObject, attribute);
+               history.add(value);
+               endTime = System.currentTimeMillis();
             }
-            catch (InterruptedException ignored)
+            catch (Exception ex)
             {
+               log.error(monitorName + " had error while monitoring", ex);
             }
+            if (recording)
+            {
+               try
+               {
+                  Thread.sleep(period);
+               }
+               catch (InterruptedException ignored)
+               {
+                  intr = true;
+               }
+            }
          }
       }
+      finally
+      {
+         if (intr) Thread.currentThread().interrupt();
+      }
    }
 
    // MBeanRegistrationImplementation overrides ---------------------

Modified: trunk/varia/src/main/org/jboss/monitor/services/MemoryMonitor.java
===================================================================
--- trunk/varia/src/main/org/jboss/monitor/services/MemoryMonitor.java	2009-05-20 03:03:17 UTC (rev 89150)
+++ trunk/varia/src/main/org/jboss/monitor/services/MemoryMonitor.java	2009-05-20 03:07:19 UTC (rev 89151)
@@ -251,24 +251,31 @@
             
             // initialise warningSamples countdown
             warningSamples = wMeasurements;
-            
-            while (!isStopRequested)
+            boolean intr = false;
+            try
             {
-               sampleMemory(wThreshold, cThreshold);
-         
-               if (!isStopRequested)
+               while (!isStopRequested)
                {
-                  try
+                  sampleMemory(wThreshold, cThreshold);
+
+                  if (!isStopRequested)
                   {
-                     Thread.sleep(samplingPeriod);
+                     try
+                     {
+                        Thread.sleep(samplingPeriod);
+                     }
+                     catch (InterruptedException e)
+                     {
+                        intr = true;
+                     }
                   }
-                  catch (InterruptedException e)
-                  {
-                     // ignored
-                  }
                }
+               log.debug("Stopped memory monitor thread");
             }
-            log.debug("Stopped memory monitor thread");
+            finally
+            {
+               if (intr) Thread.currentThread().interrupt();
+            }
          }
       };
       

Modified: trunk/varia/src/main/org/jboss/monitor/services/ScriptingListener.java
===================================================================
--- trunk/varia/src/main/org/jboss/monitor/services/ScriptingListener.java	2009-05-20 03:03:17 UTC (rev 89150)
+++ trunk/varia/src/main/org/jboss/monitor/services/ScriptingListener.java	2009-05-20 03:07:19 UTC (rev 89151)
@@ -324,59 +324,66 @@
       {
          String name = Thread.currentThread().getName();
          log.debug("Started thread: " + name);
-         
-         while (!stopRequested)
+         boolean intr = false;
+         try
          {
-            QueueEntry entry;
-            
-            synchronized (queue)
+            while (!stopRequested)
             {
-               while (queue.isEmpty() && !stopRequested)
+               QueueEntry entry;
+
+               synchronized (queue)
                {
-                  try
+                  while (queue.isEmpty() && !stopRequested)
                   {
-                     queue.wait();
+                     try
+                     {
+                        queue.wait();
+                     }
+                     catch (InterruptedException e)
+                     {
+                        Thread.currentThread().interrupt();
+                     }
                   }
-                  catch (InterruptedException e)
+
+                  if (stopRequested)
                   {
-                     // ignore
+                     // done
+                     break;
                   }
+                  else
+                  {
+                     // extract the first entry for processing
+                     entry = (QueueEntry)queue.remove(0);
+                  }
                }
-               
-               if (stopRequested)
+
+               // use this for measurement
+               long start = System.currentTimeMillis();
+
+               // we have a notification to process
+               try
                {
-                  // done
-                  break;
+                  manager.declareBean("notification", entry.notification, Notification.class);
+                  manager.declareBean("handback", entry.handback == null ? "" : entry.handback, Object.class);
+
+                  manager.exec(language, "in-memory-script", 0, 0, script);
                }
-               else
+               catch (BSFException e)
                {
-                  // extract the first entry for processing
-                  entry = (QueueEntry)queue.remove(0);
+                  log.warn("Caught exception", e);
                }
+
+               // measure time spent processing the script
+               long stop = System.currentTimeMillis();
+               totalProcessingTime.add(stop - start);
+               notificationsProcessed.increment();
             }
-            
-            // use this for measurement
-            long start = System.currentTimeMillis();
-            
-            // we have a notification to process
-            try
-            {
-               manager.declareBean("notification", entry.notification, Notification.class);
-               manager.declareBean("handback", entry.handback == null ? "" : entry.handback, Object.class);
-               
-               manager.exec(language, "in-memory-script", 0, 0, script);
-            }
-            catch (BSFException e)
-            {
-               log.warn("Caught exception", e);
-            }
-            
-            // measure time spent processing the script
-            long stop = System.currentTimeMillis();
-            totalProcessingTime.add(stop - start);
-            notificationsProcessed.increment();
+            log.debug("Stopped thread: " + name);
          }
-         log.debug("Stopped thread: " + name);
+         finally
+         {
+            if (intr) Thread.currentThread().interrupt();
+         }
       }
    }
    

Modified: trunk/varia/src/main/org/jboss/varia/process/ChildProcessService.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/process/ChildProcessService.java	2009-05-20 03:03:17 UTC (rev 89150)
+++ trunk/varia/src/main/org/jboss/varia/process/ChildProcessService.java	2009-05-20 03:07:19 UTC (rev 89151)
@@ -222,23 +222,34 @@
 
       public void run()
       {
-         while (!shutdown) {
-            try {
-               String data = reader.readLine();
-               if (data == null) {
-                  try {
-                     Thread.sleep(1000);
+         boolean intr = false;
+         try
+         {
+            while (!shutdown) {
+               try {
+                  String data = reader.readLine();
+                  if (data == null) {
+                     try {
+                        Thread.sleep(1000);
+                     }
+                     catch (InterruptedException ignore)
+                     {
+                        intr = true;
+                     }
                   }
-                  catch (InterruptedException ignore) {}
+                  else {
+                     log.log(level, data);
+                  }
                }
-               else {
-                  log.log(level, data);
+               catch (IOException e) {
+                  log.error("Failed to read data from reader", e);
                }
             }
-            catch (IOException e) {
-               log.error("Failed to read data from reader", e);
-            }
          }
+         finally
+         {
+            if (intr) Thread.currentThread().interrupt();
+         }
       }
    }
    




More information about the jboss-cvs-commits mailing list