Tag: java executorservice


  • Java – Waiting for Running Threads to Finish

    Java concurrency allows running multiple sub-tasks of a task in separate threads. Sometimes, it is necessary to wait until all the threads have finished their execution. In this tutorial, we will learn a few ways to make the current thread wait for the other threads to finish. 1. Using ExecutorService and Future.get() Java ExecutorService (or ThreadPoolExecutor) helps execute Runnable or Callable tasks asynchronously. Its submit() method returns a Future object…

  • How to Shutdown a Java ExecutorService

    ExecutorService interface provides 3 methods shutdown(), shutdownNow() and awaitTermination​() for controlling the termination of tasks submitted to executors. Learn how to use these methods under different requirements. 1. Difference between shutdown(), shutdownNow() and awaitTermination​() Let us start with checking out the syntax of these methods. void shutdown(); List<Runnable> shutdownNow(); boolean awaitTermination(long timeout, TimeUnit unit); he shutdown() initiates an orderly shutdown in which previously…

  • What is ExecutorService in Java

    Learn to use Java ExecutorService to execute a Runnable or Callable class in an asynchronous way. Also, learn the various best practices to utilize it in the most efficient manner in any Java application. 1. What is Executor Framework? In simple Java applications, we do not face many challenges while working with a few threads. If we…