now my main
function looks like this:
public static void main(String[] args) {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
new MyClass().start("192.168.1.1", 2000);
}
ExecutorService executor1 = Executors.newSingleThreadExecutor();
executor1.submit(() -> {
new MyClass().start("192.168.1.1", 2001);
}
}
In start(...)
method I have something like this :
public void start(String first, int second) {
new Thread(() -> {
....
)}.run();
}
Instead of using an executor, I would like to create a new process for each call of the start(...)
function. A process that I will be able to kill at any time. I mean something like this :
public static void main(String[] args) {
Process process= ...();
process.submit(() -> {
new MyClass().start("192.168.1.1", 2000);
}
Process process1 = ...();
process1.submit(() -> {
new MyClass().start("192.168.1.1", 2001);
}
}
And i would like to have function to stop a current process :
public void stop(Process process) {
process.kill();
}
TaskManager after call method main
and before call method stop
:
TaskManager before call method stop
TaskManager after call method stop
:
TaskManager after called method stop
I hope you understand my idea. I read another threads on this page, but there is no exatlcy the same thing what I need. Thanks :)