You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Rhuan Rocha (Jira)" <ji...@apache.org> on 2023/06/14 03:30:00 UTC
[jira] [Assigned] (CAMEL-19154) DefaultUnitOfWork may have thread security issues when I use dynamicrouter
[ https://issues.apache.org/jira/browse/CAMEL-19154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rhuan Rocha reassigned CAMEL-19154:
-----------------------------------
Assignee: Rhuan Rocha
> DefaultUnitOfWork may have thread security issues when I use dynamicrouter
> --------------------------------------------------------------------------
>
> Key: CAMEL-19154
> URL: https://issues.apache.org/jira/browse/CAMEL-19154
> Project: Camel
> Issue Type: Bug
> Components: came-core
> Affects Versions: 3.20.2
> Reporter: geyipeng
> Assignee: Rhuan Rocha
> Priority: Major
> Attachments: image-2023-03-15-20-22-22-192.png
>
>
> * 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:
> {color:#FF0000}getContext().adapt(DefaultCamelContext.class).setUnitOfWorkFactory(new MyUnitOfFactory());{color}
> {code:java}
> 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;
> }
> }{code}
> !image-2023-03-15-20-22-22-192.png!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)