Skip to main content

Command Palette

Search for a command to run...

Types of thread pool

Published
1 min read
B

Experienced Java/JavaScript full-stack developer over 6 years of extensive expertise serving key role on elite technical teams developing enterprise software for healthcare, apple ad-platform, banking, and e-commerce. Adaptable problem-solver with high levels of skill in Groovy, Java, Spring, Spring Boot, Hibernate, JavaScript, TypeScript, Angular, Node, Express, React, MongoDB, IBM DB2, Oracle, PL/SQL, Docker, Kubernetes, CI/CD pipelines, AWS, Micro-service and Agile/Scrum. Strong technical skills paired with business-savvy UI design expertise. Personable team player with experience collaborating with diverse cross-functional teams.

  1. FixedThreadPool: uses a blocking queue to store tasks

  1. CachedThreadPool: uses a synchronous queue of size 1

  1. ScheduledThreadPool: uses a delay queue

  1. SingleThreadedExecuter (sequential execution of tasks): uses a blocking queue. The size of the thread pool is 1.

     public class ThreadTypesExample {
         public static void main(String[] args) throws InterruptedException {
             ExecutorService service = Executors.newSingleThreadExecutor();
             for (int i = 0; i < 3; i++) {
                 service.execute(new Task());
             }
             System.out.println("Thread name : " +    Thread.currentThread().getName());
         }
         static class Task implements Runnable {
             @Override
             public void run() {
                 System.out.println("Thread name : " + Thread.currentThread().getName());
             }
         }
     }
    
     //output
     Thread name : main
     Thread name : pool-1-thread-1
     Thread name : pool-1-thread-1
     Thread name : pool-1-thread-1
    

More from this blog

Bikash Mainali

75 posts

Experienced Java/JavaScript full-stack developer with 8 years of extensive expertise serving key role on elite technical teams developing and designing software.