use of com.axway.ats.agent.core.threading.exceptions.ActionTaskLoaderException in project ats-framework by Axway.
the class RampUpQueueLoader method scheduleThreads.
@Override
public synchronized void scheduleThreads(String caller, boolean isUseSynchronizedIterations) throws ActionExecutionException, ActionTaskLoaderException, NoSuchComponentException, NoSuchActionException, NoCompatibleMethodFoundException, ThreadingPatternNotSupportedException {
//check the state first
if (state != ActionTaskLoaderState.NOT_STARTED) {
throw new ActionTaskLoaderException("Cannot schedule load queue " + queueName + " - it has already been scheduled");
}
//create the executor - terminate threads when finished
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
executor.setKeepAliveTime(0, TimeUnit.SECONDS);
ExecutorCompletionService<Object> executionService = new ExecutorCompletionService<Object>(executor);
//synchronization aids
threadsManagers = new ArrayList<ThreadsManager>();
// create the thread for managing max iteration length
int iterationTimeout = startPattern.getIterationTimeout();
if (iterationTimeout > 0) {
itManager = new IterationTimeoutManager(iterationTimeout);
}
taskFutures = new ArrayList<Future<Object>>();
for (int i = 0; i < numThreadGroups; i++) {
//create the thread iterations manager for this group
ThreadsManager threadsManager = new ThreadsManager();
int numThreadsInGroup = (i != numThreadGroups - 1) ? numThreadsPerStep : numThreadsInLastGroup;
//distribute executions per timeFrame according to the number of threads
int executionsPerTimeFrame = executionPattern.getExecutionsPerTimeFrame();
int[] executionsPerTimeFramePerThread = new EvenLoadDistributingUtils().getEvenLoad(executionsPerTimeFrame, numThreads);
if (numThreads > executionsPerTimeFrame && executionsPerTimeFrame > 0) {
throw new ActionTaskLoaderException("We cannot evenly distribute " + executionsPerTimeFrame + " iterations per time frame to " + numThreads + " threads. Iterations per time frame must be at least as many as threads!");
}
for (int j = 0; j < numThreadsInGroup; j++) {
Future<Object> taskFuture = executionService.submit(ActionTaskFactory.createTask(caller, queueName, executionPattern, executionsPerTimeFramePerThread[j], threadsManager, itManager, actionRequests, parameterDataProviders, defaultTaskListeners, isUseSynchronizedIterations), null);
taskFutures.add(taskFuture);
}
threadsManagers.add(threadsManager);
}
state = ActionTaskLoaderState.SCHEDULED;
}
Aggregations