I have a thread in Java which starts a HttpService.
ProcessBuilder pb = new ProceeBuilder(command);
Process process = pb.start();
process.waitFor();
I have another thread which checks if the service is started.
while (result != 0) {
ServerSocket socket = new ServerSocker(port);
socket.close();
result = 0
catch (BindException be) {
result = 1;
}
}
Now I need to somehow get information about whether the service has failed to start or it’s successfully started. I need to get this back to the Main class which started both of these threads in order to proceed. Something like
while (!started || !failed) {
wait for getting information from the threads.
}
What can you advise?
Thank you.
How about using a callback that you pass to both threads?
(omitted try-catches)