This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 8534c18e334 Add a cache for JAXB ObjectFactory lookup (#15707) 8534c18e334 is described below commit 8534c18e334528eb6bb37696197af02c05e55212 Author: Adriano Machado <60320+ammach...@users.noreply.github.com> AuthorDate: Wed Oct 2 02:33:53 2024 -0400 Add a cache for JAXB ObjectFactory lookup (#15707) --- .../src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java index cf032921b76..f1991ca1a5c 100644 --- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java +++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java @@ -17,13 +17,17 @@ package org.apache.camel.converter.jaxb; import java.lang.reflect.Method; +import java.util.Map; import jakarta.xml.bind.annotation.XmlElementDecl; import org.apache.camel.CamelContext; +import org.apache.camel.support.LRUCacheFactory; public final class JaxbHelper { + private static final Map<Class<?>, Method> JAXB_ELEMENT_FACTORY_METHODS = LRUCacheFactory.newLRUSoftCache(10, 100, true); + private JaxbHelper() { } @@ -32,6 +36,10 @@ public final class JaxbHelper { return null; } + return JAXB_ELEMENT_FACTORY_METHODS.computeIfAbsent(type, t -> findJaxbElementFactoryMethod(camelContext, t)); + } + + private static <T> Method findJaxbElementFactoryMethod(CamelContext camelContext, Class<T> type) { // find the first method that has @XmlElementDecl with one parameter that matches the type Class<?> factory = getObjectFactory(camelContext, type); if (factory != null) {