Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Cannot Reproduce
-
3.20.2
-
None
-
None
-
None
-
Unknown
Description
- This thread concurrency problem seems difficult to solve through debug, but it should be related to the DequeQue extension of org.apache.camel.impl.engine.DefaultUnitOfWork#routes that is non-thread safe
--------------------------------------------{}2023.3.16{}---------------------------------------
I'm sure this is a concurrent thread safety problem, because I inherited DefaultUnitOfWork and rewritten the pushRoute (Route route) method. After changing it to synchronized, the error disappears, but I don't know if there will be performance problems
in RouteBuilder add:
getContext().adapt(DefaultCamelContext.class).setUnitOfWorkFactory(new MyUnitOfFactory());
public class MyUnitOfWork extends DefaultUnitOfWork { public MyUnitOfWork(Exchange exchange) { super(exchange); } public MyUnitOfWork(Exchange exchange, Logger logger, InflightRepository inflightRepository, boolean allowUseOriginalMessage, boolean useBreadcrumb) { super(exchange, logger, inflightRepository, allowUseOriginalMessage, useBreadcrumb); } public MyUnitOfWork(Exchange exchange, InflightRepository inflightRepository, boolean allowUseOriginalMessage, boolean useBreadcrumb) { super(exchange, inflightRepository, allowUseOriginalMessage, useBreadcrumb); } @Override public synchronized void pushRoute(Route route) { super.pushRoute(route); } } public class MyUnitOfFactory extends DefaultUnitOfWorkFactory { private InflightRepository inflightRepository; private boolean usedMDCLogging; private String mdcLoggingKeysPattern; private boolean allowUseOriginalMessage; private boolean useBreadcrumb; @Override public UnitOfWork createUnitOfWork(Exchange exchange) { UnitOfWork answer; if (usedMDCLogging) { answer = new MDCUnitOfWork( exchange, inflightRepository, mdcLoggingKeysPattern, allowUseOriginalMessage, useBreadcrumb); } else { answer = new MyUnitOfWork(exchange, inflightRepository, allowUseOriginalMessage, useBreadcrumb); } return answer; } @Override public void afterPropertiesConfigured(CamelContext camelContext) { // optimize to read configuration once inflightRepository = camelContext.getInflightRepository(); usedMDCLogging = camelContext.isUseMDCLogging() != null && camelContext.isUseMDCLogging(); mdcLoggingKeysPattern = camelContext.getMDCLoggingKeysPattern(); allowUseOriginalMessage = camelContext.isAllowUseOriginalMessage() != null ? camelContext.isAllowUseOriginalMessage() : false; useBreadcrumb = camelContext.isUseBreadcrumb() != null ? camelContext.isUseBreadcrumb() : false; } }
Attachments
Attachments
Issue Links
- relates to
-
CAMEL-19457 camel-dynamic-router - InflightRepository size can be negative
- Resolved