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…
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…
Table Of Contents Creating a New Thread By Extending Thread Class By Implementing Runnable Interface Using Lambda Expressions Starting a New Thread Using Thread.start() Using ExecutorService Delayed Execution with ScheduledExecutorService Using CompletableFuture 1. Creating a New Thread In Java, we can create a Thread in the following ways: By extending Thread class By implementing Runnable interface Using Lambda expressions 1.1. By…