All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thoughtworks.gauge.execution.ExecutorPool Maven / Gradle / Ivy

There is a newer version: 0.11.1
Show newest version
/*----------------------------------------------------------------
 *  Copyright (c) ThoughtWorks, Inc.
 *  Licensed under the Apache License, Version 2.0
 *  See LICENSE.txt in the project root for license information.
 *----------------------------------------------------------------*/
package com.thoughtworks.gauge.execution;


import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorPool {
    private Map executors = new ConcurrentHashMap<>();

    public ExecutorPool(int size) {
        for (int count = 1; count <= size; count++) {
            executors.put(getName(count), Executors.newSingleThreadExecutor());
        }
    }

    private String getName(int count) {
        return "Executor-" + count;
    }

    public void execute(int stream, Runnable task) {
        executors.get(getName(stream)).execute(task);
    }

    public void stopAfterCompletion() {
        for (Map.Entry entry : executors.entrySet()) {
            entry.getValue().shutdown();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy