title: parallel request using JSR223 Sampler (Jmeter)
body: <p>I'm trying to use the following code (by Dmitri) in <code>JMeter 3.0</code>, however, I am unsuccessful in running it. my goal is to <strong>simulate parallel API calls</strong>.</p>
  
  <p>Any idea why its failing? code:</p>
  
  <pre><code>import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors; // necessary imports
  
  
  List&lt;String&gt; urls = new ArrayList&lt;String&gt;(); // initialize array of URLs
  Collections.addAll(urls,args); // read URLs from "Parameters" input and add them to array
  ExecutorService pool = Executors.newFixedThreadPool(urls.size()); // initialize pool of Future Tasks with number of threads equal to size of URLs provided
  for (String url : urls) { // for each URL from list
     final String currentURL = url;
     pool.submit(new Runnable() { // Sumbit a new thread which will execute GET request
  
         @Override
         public void run() {
             try {
                 HttpClient client = new DefaultHttpClient(); // Use Apache Commons HTTPClient to perform GET request
    HttpGet get = new HttpGet(currentURL);
       HttpResponse response = client.execute(get);
  HttpEntity entity = response.getEntity();
  EntityUtils.consume(entity);
             } catch (Exception ex) {
                 ex.printStackTrace();
             }
  
         }
     });
  }
  pool.shutdown(); // shut down thread pool
  </code></pre>
  
  <p><strong>Error thrown is (i did use 2 example hosts in parameter field jsr223 sampler):</strong></p>
  
  <pre><code>java.lang.IllegalStateException: Target host is null
          at org.apache.http.util.Asserts.notNull(Asserts.java:52)
          at org.apache.http.impl.conn.DefaultHttpRoutePlanner.determineRoute(DefaultHttpRoutePlanner.java:99)
          at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:763)
          at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:382)
          at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
          at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
          at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
          at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
          at org.apache.http.client.HttpClient$execute.call(Unknown Source)
          at Script3$1.run(Script3.groovy:26)
          at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
          at java.util.concurrent.FutureTask.run(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
          at java.lang.Thread.run(Unknown Source)
  </code></pre>