[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: InterruptedException not being cleared?
david.lloyd@jboss.com
do-not-reply at jboss.com
Wed Mar 4 12:25:07 EST 2009
This trivial patch gets clears the interrupt status, tolerates interrupts, and then restores the interrupt status in a finally block. Is there a reason to not do it this way? Otherwise I'll commit it, if you give the OK. Of course the forums will mangle this, but...
| Index: classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java
| ===================================================================
| --- classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java (revision 85240)
| +++ classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java (working copy)
| @@ -185,133 +185,141 @@
| * Process the next task
| *
| * @param thread the thread
| * @param task the task
| * @throws InterruptedException if it is interrupted
| */
| private static void nextTask(Thread thread, ClassLoadingTask task) throws InterruptedException
| {
| - 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;
| - }
| - }
| -
| - 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)
| - {
| - /* 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);
| + 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();
| + }
| }
| - else
| + catch (Throwable e)
| {
| if (trace)
| - log.trace("Running threadTask=" + threadTask);
| - threadTask.run();
| - }
| - }
| - 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)
| - {
| - /* Reschedule this task after all existing tasks to allow the
| - current load tasks which are conflicting to complete.
| - */
| - try
| + log.trace("Run failed with exception", e);
| + boolean retry = e instanceof ClassCircularityError || e.getClass().equals(LinkageError.class);
| + if (retry && loadTask.incrementNumCCE() < MAX_CCE)
| {
| - // Reschedule and update the loadTask.threadTaskCount
| - scheduleTask(loadTask, threadTask.getLoader(), true);
| + /* 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);
| }
| - catch (Throwable ex)
| + else
| {
| - loadTask.setLoadError(ex);
| - log.warn("Failed to reschedule task after CCE", ex);
| + loadTask.setLoadError(e);
| }
| - if (trace)
| - log.trace("Post CCE state, loadTask=" + loadTask);
| }
| - else
| + finally
| {
| - loadTask.setLoadError(e);
| + // Release any lock on the classloader
| + if (threadTask.isReleaseInNextTask())
| + threadTask.getClassLoader().unlock(false);
| }
| - }
| - finally
| - {
| - // Release any lock on the classloader
| - if (threadTask.isReleaseInNextTask())
| - threadTask.getClassLoader().unlock(false);
| - }
|
| - // If the ThreadTasks are complete mark the ClassLoadingTask finished
| - if (loadTask.getThreadTaskCount() == 0)
| - {
| - List<ThreadTask> loadTaskThreadTasks = loadTasksByThread.get(loadTask.getRequestingThread());
| - synchronized (loadTaskThreadTasks)
| + // If the ThreadTasks are complete mark the ClassLoadingTask finished
| + if (loadTask.getThreadTaskCount() == 0)
| {
| - if( trace )
| - log.trace("Notifying task of thread completion, loadTask:"+loadTask);
| - task.finish();
| - loadTaskThreadTasks.notify();
| + 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);
| + }
| + finally
| + {
| + if (intr)
| + Thread.currentThread().interrupt();
| }
| - if (trace)
| - log.trace("End nextTask(" + taskList.size()+ "), loadTask=" + loadTask);
| }
|
| /**
| * Invoked to create a ThreadTask to assign a thread to the task of
| * loading the class of ClassLoadingTask.
| *
| * @param task the classloading task
| * @param loader the loader
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4214969#4214969
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4214969
More information about the jboss-dev-forums
mailing list