title: Is ThreadLocal required for automation framework that uses Cucumber, Jmeter and FailSafe?
body: <p>Sorry if this question sounds silly.
  We are developing an automation framework that would use Java,Cucumber, Junit and Failsafe suite etc.
  There's been a suggestion to use ThreadLocal. But I am bit confused as why we need to use ThreadLocal when Junit runs the cucumber features in its own threads..</p>
  <p>The suggestion was to use ThreadLocal as shown below;-</p>
  <pre><code>public class WebDriverFactory {
  
      private static ThreadLocal&lt;WebDriver&gt; driver = new ThreadLocal&lt;&gt;();
  
      public static synchronized void setDriver(String browser) {
  
          switch (browser) {
              case &quot;chrome&quot;:
                  driver = ThreadLocal.withInitial(() -&gt; {
                      WebDriverManager.chromedriver().setup();
                      return new ChromeDriver(BrowserOptions.getChromeOptions());
                  });
          
                  break;
             
              default:
                  throw new IllegalStateException(&quot;Unexpected value: &quot; + browser);
          }
      }
  
      public static synchronized WebDriver getDriver(){
          return driver.get();
      }
  </code></pre>
  <p>Can anyone confirm if this is really required to run tests parallelly.? Also, is 'synchronized' required when using ThreadLocal?</p>