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

io.github.laskowski.shell.runner.DefaultTaskRunner Maven / Gradle / Ivy

Go to download

Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal

The newest version!
package io.github.laskowski.shell.runner;

import io.github.laskowski.shell.task.Task;

import java.util.ArrayList;
import java.util.List;

public class DefaultTaskRunner implements TaskRunner {
    private static DefaultTaskRunner taskRunner;
    private final List tasks = new ArrayList<>();

    private DefaultTaskRunner() {}

    public synchronized static DefaultTaskRunner getInstance() {
        if (taskRunner == null) {
            taskRunner = new DefaultTaskRunner();
        }
        return taskRunner;
    }

    @Override
    public void run(Task task) {
        Thread taskThread = new Thread(task::start);
        taskThread.start();

        tasks.add(task);
    }

    @Override
    public void stop(Task task) {
        tasks.remove(task);
        task.stop();
    }

    @Override
    public void stopAll() {
        tasks.forEach(Task::stop);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy