title: How to achieve multithreading on Mongo Async Java Driver?
body: <p>I am trying to achieve a high throughput of Inserts/Second on a Spring application (without Spring data). I try to insert a million documents with the following code:</p>
  
  <pre><code>Address address = new Address();
  address.setStreet1("");
  address.setStreet2("");
  address.setZipCode("");
  address.setId(1234);
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  IntStream.iterate(0, i -&gt; i++).limit(1000000).parallel().
            forEach(i -&gt; addressRepository.insert(address);
  stopWatch.stop();
  </code></pre>
  
  <p>And the repository code as follows:</p>
  
  <pre><code>public void insert(Address address) {
         Document address = new Document("_id", address.getId()).
                           append("zip_code", address.getZipCode).
                           append("street_1", address.getStreet1()).
                           append("street_2", address.getStreet2());
  
        db.getCollection("address").insertOne(address, (Void result, Throwable t)
                                        -&gt; System.out.println("Inserted"));
  }
  </code></pre>
  
  <p>The maximum number of writes I could muster was around 4k/second. Is there any way to do this in a multithreaded way to get much higher writes per second?</p>
  
  <p>My Spring bean configuration for MongoClient is:</p>
  
  <pre><code> @Bean
   public MongoClient mongoClient() {
          return MongoClients.create("mongodb://localhost");
   }
  </code></pre>