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

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

commit feb4d5f03a2b90878608c01f94f67ce2ac1eb9f8
Author: Felix Schumacher <[email protected]>
AuthorDate: Sun Aug 25 21:13:02 2019 +0200

    Convert to ThreadLocal#withInitial
---
 .../org/apache/jmeter/functions/Jexl3Function.java | 35 +++++++++-------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git 
a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java 
b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java
index bacc4f3..2b1f2d7 100644
--- a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java
+++ b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java
@@ -49,7 +49,8 @@ public class Jexl3Function extends AbstractFunction 
implements ThreadListener {
 
     private static final List<String> desc = new LinkedList<>();
 
-    private static final ThreadLocal<JexlEngine> threadLocalJexl = new 
ThreadLocal<>();
+    private static final ThreadLocal<JexlEngine> threadLocalJexl = ThreadLocal
+            .withInitial(Jexl3Function::createJexlEngine);
 
     static
     {
@@ -91,7 +92,7 @@ public class Jexl3Function extends AbstractFunction 
implements ThreadListener {
             jc.set("OUT", System.out);//$NON-NLS-1$
 
             // Now evaluate the script, getting the result
-            JexlScript e = getJexlEngine().createScript(exp);
+            JexlScript e = threadLocalJexl.get().createScript(exp);
             Object o = e.execute(jc);
             if (o != null)
             {
@@ -108,25 +109,16 @@ public class Jexl3Function extends AbstractFunction 
implements ThreadListener {
         return str;
     }
 
-    /**
-     * Get JexlEngine from ThreadLocal
-     * @return JexlEngine
-     */
-    private static JexlEngine getJexlEngine() {
-        JexlEngine engine = threadLocalJexl.get();
-        if(engine == null) {
-            engine = new JexlBuilder()
-                    .cache(512)
-                    .silent(true)
-                    .strict(true)
-                    // debug is true by default an impact negatively 
performances
-                    // by a factory of 10
-                    // Use JexlInfo if necessary
-                    .debug(false)
-                    .create();
-            threadLocalJexl.set(engine);
-        }
-        return engine;
+    private static JexlEngine createJexlEngine() {
+        return new JexlBuilder()
+                .cache(512)
+                .silent(true)
+                .strict(true)
+                // debug is true by default an impact negatively performances
+                // by a factory of 10
+                // Use JexlInfo if necessary
+                .debug(false)
+                .create();
     }
 
     /** {@inheritDoc} */
@@ -154,6 +146,7 @@ public class Jexl3Function extends AbstractFunction 
implements ThreadListener {
 
     @Override
     public void threadStarted() {
+        // nothing to do on thread startup
     }
 
     @Override

Reply via email to