Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package ru.sberbank;
  2.  
  3. public class MyExecutionManager implements ExecutionManager {
  4.  
  5.   private final FixedThreadPool threadPool;
  6.  
  7.   MyExecutionManager(FixedThreadPool threadPool) {
  8.  
  9.     this.threadPool = threadPool;
  10.   }
  11.  
  12.   @Override
  13.   public Context execute(Runnable callback, Runnable... tasks) {
  14.  
  15.     for (Runnable task : tasks) {
  16.       threadPool.execute(task);
  17.     }
  18.     threadPool.execute(callback);
  19.  
  20.     return new Context() {
  21.       @Override
  22.       public int getCompletedTaskCount() {
  23.         return threadPool.getCompletedTasks();
  24.       }
  25.  
  26.       @Override
  27.       public int getFailedTaskCount() {
  28.         return threadPool.getFailedTasks();
  29.       }
  30.  
  31.       @Override
  32.       public int getInterruptedTaskCount() {
  33.         return threadPool.getQueueSize();
  34.       }
  35.  
  36.       @Override
  37.       public void interrupt() {
  38.         threadPool.shutdown();
  39.       }
  40.  
  41.       @Override
  42.       public boolean isFinished() {
  43.         return threadPool.getQueueSize() == 0;
  44.       }
  45.     };
  46.   }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement