title: java.lang.OutOfMemoryError: unable to create new native thread executing Selenium WebDriver based tests using Selenium and Java
body: <p>I am running more than 2000s selenium tests which are migrated from Selenium RC to WebDriver using selenium-leg-rc.jar (a kind of bridge library) which allow to compile/execute RC based test code using WebDriver.</p>
  
  <p>These tests are executed in 4 parallel processes by splitting into 4 groups. Approx 50% tests run fine and after that I see firefox and gecodriver processes are not killing consistently while I am invoking driver.quit() at the end of every tests. After this, I randomly get SocketTimeoutException/OutOfMemoryError errors as below call stack.</p>
  
  <pre><code>[junit] Exception in thread "ForkJoinPool.commonPool-worker-0" java.lang.OutOfMemoryError: unable to create new native thread
  [junit]     at java.lang.Thread.start0(Native Method)
  [junit]     at java.lang.Thread.start(Thread.java:714)
  [junit]     at java.util.concurrent.ForkJoinPool.tryAddWorker(ForkJoinPool.java:1338)
  [junit]     at java.util.concurrent.ForkJoinPool.deregisterWorker(ForkJoinPool.java:1460)
  [junit]     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:167)
           . . .
           . . .
           . . .
  
  [junit] org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout
  [junit] Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
  [junit] System info: host: 'mylinuxbox', ip: '101.24.15.172', os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.13-118.36.1.el6uek.x86_64', java.version: '1.8.0_20-ea'
  [junit] Driver info: driver.version: RemoteWebDriver
  [junit]     at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
  </code></pre>
  
  <p>If I run these tests in a single process all works fine. Any suggestion apart from using Runner classes to run multiple threads instead of processes or doing clean WebDriver approach. Similar problem with Windows 10 also.</p>
  
  <p>Selenium 3.141.59
  geckodriver 0.25
  Firefox 60.8.0b8</p>