package edu.javacourse.threads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Artem Pronchakov | email/xmpp: artem.pronchakov@calisto.email
 */
public class ExecutorServiceExample {

    public static void main(String[] args) {

        Thread worker1 = new Thread(new Worker("worker1"));
        Thread worker2 = new Thread(new Worker("worker2"));
        Thread worker3 = new Thread(new Worker("worker3"));
        Thread worker4 = new Thread(new Worker("worker4"));
        Thread worker5 = new Thread(new Worker("worker5"));

//        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        executorService.execute(worker1);
        executorService.execute(worker2);
        executorService.execute(worker3);
        executorService.execute(worker4);
        executorService.execute(worker5);

        executorService.shutdown();

    }

}

@@ -281,30 +281,30 @@
  %7B%0A%0A        
-Thread
+Worker
  worker1 = n
@@ -302,35 +302,24 @@
 rker1 = new 
-Thread(new 
 Worker(%22work
@@ -323,17 +323,16 @@
 orker1%22)
-)
 ;%0A      
@@ -329,30 +329,30 @@
 %22);%0A        
-Thread
+Worker
  worker2 = n
@@ -350,35 +350,24 @@
 rker2 = new 
-Thread(new 
 Worker(%22work
@@ -371,17 +371,16 @@
 orker2%22)
-)
 ;%0A      
@@ -377,30 +377,30 @@
 %22);%0A        
-Thread
+Worker
  worker3 = n
@@ -398,35 +398,24 @@
 rker3 = new 
-Thread(new 
 Worker(%22work
@@ -419,17 +419,16 @@
 orker3%22)
-)
 ;%0A      
@@ -425,30 +425,30 @@
 %22);%0A        
-Thread
+Worker
  worker4 = n
@@ -446,35 +446,24 @@
 rker4 = new 
-Thread(new 
 Worker(%22work
@@ -467,17 +467,16 @@
 orker4%22)
-)
 ;%0A      
@@ -477,22 +477,22 @@
         
-Thread
+Worker
  worker5
@@ -502,19 +502,8 @@
 new 
-Thread(new 
 Work
@@ -515,17 +515,16 @@
 orker5%22)
-)
 ;%0A%0A//   

Remove unnecessary Thread objects creation in ExecutorService