You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/01/31 05:24:33 UTC

[camel] 03/08: CAMEL-14354: camel-core optimize

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 997f777c903667ea5ee82ea9087ae441e8637f53
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 30 09:48:08 2020 +0100

    CAMEL-14354: camel-core optimize
---
 .../camel/impl/engine/AbstractCamelContext.java    | 25 ++++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 8bb39dd..b4853da 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -3297,6 +3297,8 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
      * components and create routes
      */
     protected void forceLazyInitialization() {
+        initEagerMandatoryServices();
+
         if (initialization != Initialization.Lazy) {
             doStartStandardServices();
 
@@ -3306,6 +3308,22 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
         }
     }
 
+    /**
+     * Initializes eager some mandatory services which needs to warmup and
+     * be ready as this helps optimize Camel at runtime.
+     */
+    protected void initEagerMandatoryServices() {
+        if (headersMapFactory == null) {
+            // we want headers map to be created as then JVM can optimize using it as we use it per exchange/message
+            synchronized (lock) {
+                if (headersMapFactory == null) {
+                    setHeadersMapFactory(createHeadersMapFactory());
+                }
+            }
+        }
+    }
+
+
     protected void doStartStandardServices() {
         getVersion();
         getTypeConverter();
@@ -4081,13 +4099,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
 
     @Override
     public HeadersMapFactory getHeadersMapFactory() {
-        if (headersMapFactory == null) {
-            synchronized (lock) {
-                if (headersMapFactory == null) {
-                    setHeadersMapFactory(createHeadersMapFactory());
-                }
-            }
-        }
         return headersMapFactory;
     }