ResultPage<TaskProgress> terminate(final FindTaskCriteria criteria) {
        return securityContext.secureResult(AppPermission.MANAGE_TASKS_PERMISSION, () -> {
            // This can change a little between servers
            final long timeNowMs = System.currentTimeMillis();

            final List<TaskProgress> taskProgressList = new ArrayList<>();

            if (criteria != null && criteria.isConstrained()) {
                final List<TaskContextImpl> terminateList = new ArrayList<>();

                // Loop over all of the tasks that this node knows about and see if
                // it should be terminated.
                for (final TaskContextImpl taskContext : taskRegistry.list()) {
                    final TaskId taskId = taskContext.getTaskId();

                    // Terminate it?
                    if (!taskContext.isTerminated()) {
                        if (criteria.isMatch(taskId, taskContext.getSessionId())) {
                            terminateList.add(taskContext);
                        }
                    }
                }

                // Now terminate the relevant tasks.
                doTerminated(timeNowMs, taskProgressList, terminateList);
            }

            return ResultPage.createUnboundedList(taskProgressList);
        });
    }
Tells tasks to terminate and waits for all tasks to terminate before
cleaning up the executors.
stroom-task/stroom-task-impl/src/main/java/stroom/task/impl/TaskManagerImpl.java