[ 
https://issues.apache.org/jira/browse/CAMEL-6485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13692167#comment-13692167
 ] 

Eric commented on CAMEL-6485:
-----------------------------

Something is wrong with my Eclipse...  The modification is very small, so until 
I figure what is wrong, here is the new code:

Before:
{code}
    public ManagementStrategy getManagementStrategy() {
        synchronized (managementStrategyInitialized) {
            if (managementStrategyInitialized.compareAndSet(false, true)) {
                managementStrategy = createManagementStrategy();
            }
            return managementStrategy;
        }
    }
{code}

After:
{code}
    public ManagementStrategy getManagementStrategy() {
        if (!managementStrategyInitialized.get()) {
            synchronized (managementStrategyInitialized) {
                if (managementStrategyInitialized.compareAndSet(false, true)) {
                    managementStrategy = createManagementStrategy();
                }
            }
        }
        return managementStrategy;
    }
{code}

I check the state of the boolean before entering the synchronized block.
                
> Performance improvement in DefaultCamelContext by delaying synchronized block
> -----------------------------------------------------------------------------
>
>                 Key: CAMEL-6485
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6485
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.11.0
>            Reporter: Eric
>              Labels: performance
>         Attachments: defaultcamelcontext.patch
>
>
> When using Camel in a hi-throughput/multithreaded environment, I see a lot of 
> contention in the DefaultCamelContext.getManagementStrategy() method.  Camel 
> is synchronizing on an AtomicBoolean no matter what is the value of the 
> boolean.  It is only required if the managementStrategy has not been 
> initialized yet.  I have attached a patch that delays the synchronization to 
> when the managementStrategy is not initialized.  This dramatically improved 
> the performance of my system.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to