Advertisement
myshkin1

Untitled

Apr 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.concurrent.*;
  2.  
  3. class LionPenManager {
  4.     private void removeAnimals() {
  5.         System.out.println("Removing animals");
  6.     }
  7.  
  8.     private void cleanPen() {
  9.         System.out.println("Cleaning the pen");
  10.     }
  11.  
  12.     private void addAnimals() {
  13.         System.out.println("Adding animals");
  14.     }
  15.  
  16.     public void performTask() {
  17.         removeAnimals();
  18.         cleanPen();
  19.         addAnimals();
  20.     }
  21.  
  22.     public static void main(String[] args) {
  23.         ExecutorService service = null;
  24.         try {
  25.             service = Executors.newFixedThreadPool(4);
  26.             LionPenManager manager = new LionPenManager();
  27.             for (int i = 0; i < 4; i++)
  28.                 service.submit(() -> manager.performTask());
  29.         } finally {
  30.             if (service != null) service.shutdown();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement