title: Unable to solve "Uncaught Exception java.lang.OutOfMemoryError: unable to create new native thread" when testing with multiple threads in JMeter
body: <p>I am load testing MQTT connection with JMeter. </p>
  
  <p>The test runs in NON-GUI mode. 
  All listeners were disabled during the test. </p>
  
  <p>Everything was fine until I increased thread number from 2k to 3k. Now, this error occurs when I am running the test:</p>
  
  <pre><code>Uncaught Exception java.lang.OutOfMemoryError: unable to create new native thread. See log file for details.
  </code></pre>
  
  <p>I tried increasing the HEAP size by editing the executable file "jmeter"<a href="https://i.stack.imgur.com/DaL4a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DaL4a.png" alt="enter image description here"></a></p>
  
  <p>Here is how I edited it. I changed it from 512m to 1024m:
  <a href="https://i.stack.imgur.com/Eh98a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Eh98a.png" alt="enter image description here"></a></p>
  
  <p>But it doesn't work. Then I changed to a larger value 2048m, still doesn't work.</p>
  
  <p>I searched for this problem and found out that it might have something to do with the thread stack size. Some pointed out that I may set the thread stack size in the script too. So I tried adding the thread stack size in the executable file.</p>
  
  <p>This is how I did it:
  <a href="https://i.stack.imgur.com/LsJDQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LsJDQ.png" alt="enter image description here"></a></p>
  
  <p>I am not sure if it is the correct way. It didn't work too.</p>
  
  <p>Some also says that maybe the HEAP size or the Thread stack size of the JVM should be increased.</p>
  
  <p>Then I came across this tutorial by MKYoung:<a href="https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/" rel="nofollow noreferrer">https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/</a>
  stating the ways to change the HEAP size and the thread stack size of java.</p>
  
  <p>But for setting to work I have to state a java class file at the end of the command.</p>
  
  <pre><code>java -Xss256k &lt;class name here&gt;
  </code></pre>
  
  <p>But the Jmeter is unix executable and there doesn't seem to be any java class files there.</p>
  
  <p>I am really running out of ways. Please help. </p>