I tried making the default thread pool size 1, but didnt seem to work ie

 <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring";>
    <package>com.nomura.fiet.stp.radial</package>
    <threadPoolProfile id="singleThreadedProfile"
                       defaultProfile="true"
                       maxPoolSize="1"
                       poolSize="1"
                       rejectedPolicy="Abort" />
  </camelContext>

In the end I implemented an explicit lock:

public class CamelRouteLock {

    private final ReentrantLock lock = new ReentrantLock();
    private final long timeoutMillis;
    private final String name;

    public CamelRouteLock(String name, long timeoutMillis) {
        this.name = name;
        this.timeoutMillis = timeoutMillis;
    }

    public void lockForDurationOfExchange(Exchange exchange) throws
InterruptedException {
        boolean locked = lock.tryLock(timeoutMillis, TimeUnit.MILLISECONDS);
        if (locked) {
            exchange.getUnitOfWork().addSynchronization(new
LockSynchronization());
        } else {
            throw new RuntimeException("Timeout occured - failed to obtain
lock: " + name + " within " + timeoutMillis + " milliseconds");
        }
    }

    /**
     * On success or failure make sure the lock is released
     */
    class LockSynchronization implements Synchronization {
        @Override
        public void onComplete(Exchange exchange) {
            lock.unlock();
        }

        @Override
        public void onFailure(Exchange exchange) {
            lock.unlock();
        }
    }
}


--
View this message in context: 
http://camel.465427.n5.nabble.com/Enforcing-a-single-thread-of-execution-across-all-routes-tp4980536p4981193.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to