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 2021/03/14 10:56:40 UTC

[camel] 03/05: CAMEL-16353: camel-core - Force eager classloading in build phase

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 7300fa5fb2e77f561476cdce9e31dc9509bdad00
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 14 09:49:00 2021 +0100

    CAMEL-16353: camel-core - Force eager classloading in build phase
---
 .../org/apache/camel/impl/engine/DefaultReactiveExecutor.java  | 10 ++++++++++
 .../camel/processor/errorhandler/RedeliveryErrorHandler.java   |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
index a2cb45b..f9e5d1d 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
@@ -99,6 +99,16 @@ public class DefaultReactiveExecutor extends ServiceSupport implements ReactiveE
     }
 
     @Override
+    protected void doBuild() throws Exception {
+        super.doBuild();
+
+        // force to create and load the class during build time so the JVM does not
+        // load the class on first exchange to be created
+        Worker dummy = new Worker(0, this);
+        LOG.trace("Warming up DefaultReactiveExecutor loaded class: {}", dummy.getClass().getName());
+    }
+
+    @Override
     protected void doStop() throws Exception {
         if (LOG.isDebugEnabled() && statisticsEnabled) {
             LOG.debug("Stopping DefaultReactiveExecutor [createdWorkers: {}, runningWorkers: {}, pendingTasks: {}]",
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index 544de26..1481748 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -21,7 +21,6 @@ import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -1588,6 +1587,11 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
         simpleTask = deadLetter == null && !redeliveryEnabled && (exceptionPolicies == null || exceptionPolicies.isEmpty())
                 && onPrepareProcessor == null;
 
+        // force to create and load the class during build time so the JVM does not
+        // load the class on first exchange to be created
+        Object dummy = simpleTask ? new SimpleTask() : new RedeliveryTask();
+        LOG.trace("Warming up RedeliveryErrorHandler loaded class: {}", dummy.getClass().getName());
+
         boolean pooled = camelContext.adapt(ExtendedCamelContext.class).getExchangeFactory().isPooled();
         if (pooled) {
             taskFactory = new PooledTaskFactory() {