diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java b/org.springframework.integration/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java
index e990f4236a..870d0d650f 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,15 @@ package org.springframework.integration.dispatcher;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.springframework.core.OrderComparator;
+import org.springframework.core.Ordered;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageHandler;
@@ -31,6 +36,14 @@ import org.springframework.util.Assert;
/**
* Base class for {@link MessageDispatcher} implementations.
*
+ *
The {@link Comparator} that determines the order may be provided via the
+ * {@link #setComparator(Comparator)} method. If none is provided, the default
+ * will be an instance of {@link OrderComparator}, and any {@link MessageHandler}
+ * that implements {@link org.springframework.core.Ordered} and has an order
+ * value other than LOWEST_PRECEDENCE will be ordered accordingly. Any other
+ * handlers will be placed at the end of the list in their original
+ * insertion-order.
+ *
* @author Mark Fisher
* @author Iwein Fuld
*/
@@ -38,10 +51,26 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
protected final Log logger = LogFactory.getLog(this.getClass());
- private final List handlers = new ArrayList();
+ private volatile List handlers = new LinkedList();
+
+ @SuppressWarnings("unchecked")
+ private volatile Comparator