Java — Thread Pools (Executor Framework) | Code Factory

Index Page : Link

Donate : Link

WordPress Blog : Link

  • Creating a new thread for every job may create performance on memory problems, to overcome this we should go for Thread Pool.
  • Thread pool is a pool of already created threads, ready to do out job.
  • Java 1.5v introduces thread pool framework to implement thread pools. Thread Pool also know as executor framework.
  • We can create a thread pool as foolows.
  • We can submit a Runnable job by using a submit method service.submit(job).
  • We can shutdown executor service by using shutdown method service.shutdown().

Output :

  • In the above exmple 3 threads are responsible to execute 6 jobs. So that a single thread can be reuse for multiple jons.
  • While designing web servers and application servers we can use thread pool concept.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store