title: What is the difference between asynchronous with waiting for result and synchronous?
body: <p>Recently, I am learning multi-threading and asynchronous programing in java, while I found this confusing.</p>
  <p>To be clear about my question: Are the codes below equivalent?</p>
  <ul>
  <li><p>If no, why? In my opinion, in the first snippet, the while loop will keep the original thread busy (meaning blocking?).</p>
  </li>
  <li><p>If yes, how to use asynchronous properly?</p>
  </li>
  </ul>
  <pre><code>//asynchronous programing
  
  ExecutorService threadpool = Executors.newCachedThreadPool();
  Future&lt;Long&gt; futureTask = threadpool.submit(() -&gt; factorial(number));
  
  while (!futureTask.isDone()) {
      System.out.println(&quot;FutureTask is not finished yet...&quot;); 
  } 
  long result = futureTask.get(); 
  
  threadpool.shutdown();
  </code></pre>
  <pre><code>//synchronous
  long result = factorial(number)
  </code></pre>