Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.sberbank;
- public class MyExecutionManager implements ExecutionManager {
- private final FixedThreadPool threadPool;
- MyExecutionManager(FixedThreadPool threadPool) {
- this.threadPool = threadPool;
- }
- @Override
- public Context execute(Runnable callback, Runnable... tasks) {
- for (Runnable task : tasks) {
- threadPool.execute(task);
- }
- threadPool.execute(callback);
- return new Context() {
- @Override
- public int getCompletedTaskCount() {
- return threadPool.getCompletedTasks();
- }
- @Override
- public int getFailedTaskCount() {
- return threadPool.getFailedTasks();
- }
- @Override
- public int getInterruptedTaskCount() {
- return threadPool.getQueueSize();
- }
- @Override
- public void interrupt() {
- threadPool.shutdown();
- }
- @Override
- public boolean isFinished() {
- return threadPool.getQueueSize() == 0;
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement