io.github.laskowski.shell.runner.DefaultTaskRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shell-commander Show documentation
Show all versions of shell-commander Show documentation
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);
}
}