Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-19098

Possible performance issue invoking a bean method with a string parameter

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      Hi,

       

      As discussed in the Camel users email thread - https://lists.apache.org/thread/3whp1726zttcckh20tdn0j9wj9vt6tgd

       

      I have noticed that when invoking a bean method with a string parameter, it works but a very special handling is needed to avoid a performance hit. Example code below.

      When the parameter is not single quoted or double quoted - Camel tries to resolve the value and in the process tries to load a class by that name which is a very expensive process. This behavior is expected IMO.
      When the parameter is single quoted or double quoted - Camel still tries to resolve the value as a class name. IMO this is not behaving properly.

      This issue happens because "StringQuoteHelper.splitSafeQuote(methodParameters, ',', true);" invoked in "MethodInfo.ParameterExpression#evaluate" removes the single/double quotes.
      Inside "MethodInfo.evaluateParameterValue" the "BeanHelper.isValidParameterValue(exp)" is invoked and returns false and therefor "BeanHelper.isAssignableToExpectedType" > ... > "DefaultClassResolver.loadClass(String name, ClassLoader loader)" is invoked every time the bean method is invoked.

      The current workaround I found is to add both types of quotes. With this workaround, "MethodInfo.ParameterExpression#evaluate" removes the outer set of quotes but keeps the inner one and "BeanHelper.isValidParameterValue(exp)" returns true.

       

      public class MyRouteBuilder extends RouteBuilder {
          @Override
          public void configure() throws Exception {
              from("timer:foo?period=2000")
                  .to("bean:myBean?method=myMethod(slow)")
                  .to("bean:myBean?method=myMethod('alsoSlow1')")
                  .to("bean:myBean?method=myMethod(\"alsoSlow2\")")
                  .to("bean:myBean?method=myMethod(\"'fast'\")");
      {{    }}}
      }

      public class MyBean {
          public void myMethod(String str) {
              System.out.println("str = " + str);
      {{    }}}
      }

       

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              elishamoshe Moshe Elisha
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: