[jboss-cvs] JBossAS SVN: r85260 - projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 4 17:56:11 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-03-04 17:56:10 -0500 (Wed, 04 Mar 2009)
New Revision: 85260

Modified:
   projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
   projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java
Log:
(Merge from 2.x branch) Fix interrupt handling for JBAS-6546 (and others?)

Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2009-03-04 22:51:44 UTC (rev 85259)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2009-03-04 22:56:10 UTC (rev 85260)
@@ -954,6 +954,7 @@
       }
       catch (InterruptedException ignored)
       {
+         interrupted = true;
       }
       finally
       {
@@ -1017,6 +1018,7 @@
             }
             catch (InterruptedException ignored)
             {
+               interrupted = true;
             }
          }
       }

Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java	2009-03-04 22:51:44 UTC (rev 85259)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java	2009-03-04 22:56:10 UTC (rev 85260)
@@ -147,15 +147,7 @@
    {
       while (task.getThreadTaskCount() != 0)
       {
-         try
-         {
-            nextTask(thread, task);
-         }
-         catch(InterruptedException e)
-         {
-            task.setLoadError(e);
-            break;
-         }
+         nextTask(thread, task);
       }
 
       Class<?> loadedClass = task.getLoadedClass();
@@ -186,127 +178,134 @@
     * 
     * @param thread the thread
     * @param task the task
-    * @throws InterruptedException if it is interrupted
     */
-   private static void nextTask(Thread thread, ClassLoadingTask task) throws InterruptedException
+   private static void nextTask(Thread thread, ClassLoadingTask task)
    {
-      boolean trace = log.isTraceEnabled();
-      if (trace)
-         log.trace("Next task thread=" + thread + " task=" + task);
-      
-      List<ThreadTask> taskList = loadTasksByThread.get(thread);
-      synchronized (taskList)
+      boolean intr = Thread.interrupted();
+      try
       {
-         // There may not be any ThreadTasks
-         while (taskList.isEmpty() && task.getThreadTaskCount() != 0 )
+         boolean trace = log.isTraceEnabled();
+         if (trace)
+            log.trace("Next task thread=" + thread + " task=" + task);
+
+         List<ThreadTask> taskList = loadTasksByThread.get(thread);
+         synchronized (taskList)
          {
-            /* There are no more tasks for the calling thread to execute, so the
-            calling thread must wait until the task.threadTaskCount reaches 0
-             */
-            if (trace)
-               log.trace("Begin nextTask(WAIT_ON_EVENT), task="+task);
-            try
+            // There may not be any ThreadTasks
+            while (taskList.isEmpty() && task.getThreadTaskCount() != 0 )
             {
-               task.waitOnEvent();
-               taskList.wait();
+               /* There are no more tasks for the calling thread to execute, so the
+               calling thread must wait until the task.threadTaskCount reaches 0
+                */
+               if (trace)
+                  log.trace("Begin nextTask(WAIT_ON_EVENT), task="+task);
+               try
+               {
+                  task.waitOnEvent();
+                  taskList.wait();
+                  if (trace)
+                     log.trace("nextTask(WAIT_ON_EVENT), notified, task="+task);
+               }
+               catch(InterruptedException e)
+               {
+                  if( trace )
+                     log.trace("nextTask(WAIT_ON_EVENT), interrupted, task="+task, e);
+                  intr = true;
+               }
             }
-            catch(InterruptedException e)
+
+            if (trace)
+               log.trace("Continue nextTask(" + taskList.size()+"), task="+task);
+
+            // See if the task is complete
+            if (task.getThreadTaskCount() == 0)
             {
-               if( trace )
-                  log.trace("nextTask(WAIT_ON_EVENT), interrupted, task="+task, e);
-               // Abort this task t
-               throw e;
+               task.finish();
+               log.trace("End nextTask(FINISHED), task="+task);
+               return;
             }
-            if (trace)
-               log.trace("nextTask(WAIT_ON_EVENT), notified, task="+task);
          }
 
+         ThreadTask threadTask = taskList.remove(0);
+         ClassLoadingTask loadTask = threadTask.getLoadTask();
          if (trace)
-            log.trace("Continue nextTask(" + taskList.size()+"), task="+task);
+            log.trace("Begin nextTask(" + taskList.size() + "), loadTask=" + loadTask);
 
-         // See if the task is complete
-         if (task.getThreadTaskCount() == 0)
+         try
          {
-            task.finish();
-            log.trace("End nextTask(FINISHED), task="+task);
-            return;
+            Thread taskThread = threadTask.getThread();
+            if (taskThread == null)
+            {
+               /* This is a task that has been reassigned back to the original
+               requesting thread ClassLoadingTask, so a new ThreadTask must
+               be scheduled.
+               */
+               if (trace)
+                  log.trace("Rescheduling threadTask=" + threadTask);
+               scheduleTask(loadTask, threadTask.getLoader(), true);
+            }
+            else
+            {
+               if (trace)
+                  log.trace("Running threadTask=" + threadTask);
+               threadTask.run();
+            }
          }
-      }
-
-      ThreadTask threadTask = taskList.remove(0);
-      ClassLoadingTask loadTask = threadTask.getLoadTask();
-      if (trace)
-         log.trace("Begin nextTask(" + taskList.size() + "), loadTask=" + loadTask);
-
-      try
-      {
-         Thread taskThread = threadTask.getThread();
-         if (taskThread == null)
+         catch (Throwable e)
          {
-            /* This is a task that has been reassigned back to the original
-            requesting thread ClassLoadingTask, so a new ThreadTask must
-            be scheduled.
-            */
             if (trace)
-               log.trace("Rescheduling threadTask=" + threadTask);
-            scheduleTask(loadTask, threadTask.getLoader(), true);
+               log.trace("Run failed with exception", e);
+            boolean retry = e instanceof ClassCircularityError || e.getClass().equals(LinkageError.class);
+            if (retry && loadTask.incrementNumCCE() < MAX_CCE)
+            {
+               /* Reschedule this task after all existing tasks to allow the
+               current load tasks which are conflicting to complete.
+               */
+               try
+               {
+                  // Reschedule and update the loadTask.threadTaskCount
+                  scheduleTask(loadTask, threadTask.getLoader(), true);
+               }
+               catch (Throwable ex)
+               {
+                  loadTask.setLoadError(ex);
+                  log.warn("Failed to reschedule task after CCE", ex);
+               }
+               if (trace)
+                  log.trace("Post CCE state, loadTask=" + loadTask);
+            }
+            else
+            {
+               loadTask.setLoadError(e);
+            }
          }
-         else
+         finally
          {
-            if (trace)
-               log.trace("Running threadTask=" + threadTask);
-            threadTask.run();
+            // Release any lock on the classloader
+            if (threadTask.isReleaseInNextTask())
+               threadTask.getClassLoader().unlock(false);
          }
-      }
-      catch (Throwable e)
-      {
-         if (trace)
-            log.trace("Run failed with exception", e);
-         boolean retry = e instanceof ClassCircularityError || e.getClass().equals(LinkageError.class);
-         if (retry && loadTask.incrementNumCCE() < MAX_CCE)
+
+         // If the ThreadTasks are complete mark the ClassLoadingTask finished
+         if (loadTask.getThreadTaskCount() == 0)
          {
-            /* Reschedule this task after all existing tasks to allow the
-            current load tasks which are conflicting to complete.
-            */
-            try
+            List<ThreadTask> loadTaskThreadTasks = loadTasksByThread.get(loadTask.getRequestingThread());
+            synchronized (loadTaskThreadTasks)
             {
-               // Reschedule and update the loadTask.threadTaskCount
-               scheduleTask(loadTask, threadTask.getLoader(), true);
+               if( trace )
+                  log.trace("Notifying task of thread completion, loadTask:"+loadTask);
+               task.finish();
+               loadTaskThreadTasks.notify();
             }
-            catch (Throwable ex)
-            {
-               loadTask.setLoadError(ex);
-               log.warn("Failed to reschedule task after CCE", ex);
-            }
-            if (trace)
-               log.trace("Post CCE state, loadTask=" + loadTask);
          }
-         else
-         {
-            loadTask.setLoadError(e);
-         }
+         if (trace)
+            log.trace("End nextTask(" + taskList.size()+ "), loadTask=" + loadTask);
       }
       finally
       {
-         // Release any lock on the classloader
-         if (threadTask.isReleaseInNextTask())
-            threadTask.getClassLoader().unlock(false);
+         if (intr)
+            Thread.currentThread().interrupt();
       }
-
-      // If the ThreadTasks are complete mark the ClassLoadingTask finished
-      if (loadTask.getThreadTaskCount() == 0)
-      {
-         List<ThreadTask> loadTaskThreadTasks = loadTasksByThread.get(loadTask.getRequestingThread());
-         synchronized (loadTaskThreadTasks)
-         {
-            if( trace )
-               log.trace("Notifying task of thread completion, loadTask:"+loadTask);
-            task.finish();
-            loadTaskThreadTasks.notify();
-         }
-      }
-      if (trace)
-         log.trace("End nextTask(" + taskList.size()+ "), loadTask=" + loadTask);
    }
 
    /** 
@@ -391,6 +390,7 @@
                   }
                   catch (InterruptedException ignored)
                   {
+                     interrupted = true;
                   }
                   thread = loadClassThreads.get(classLoader);
                }




More information about the jboss-cvs-commits mailing list