Welcome to the third part of my tutorial series on Java concurrency. In this tutorial, we will learn how to manage threads in our application using executors and thread pools. In the previous tutorial, we learned how to create threads in Java by extending the Thread class or implementing the Runnable interface. While it is easy to create one or two threads and run them, it becomes a problem when your application requires creating 20 or 30 threads for running tasks concurrently.Īlso, it won’t be exaggerating to say that large multi-threaded applications will have hundreds, if not thousands of threads running simultaneously.
So, it makes sense to separate thread creation and management from the rest of the application.Įnter Executors, A framework for creating and managing threads. Thread Creation: It provides various methods for creating threads, more specifically a pool of threads, that your application can use to run tasks concurrently. I think if people saw me, it probably looked very unofficial, chuckles Hallgren.
Keeping Becoming clandestine still wasn’t easy, though. Thread Management: It manages the life cycle of the threads in the thread pool. My closest friends had no idea what I was doing, Hallgren says.