I would like to close all threads that are running (if there are) when my main method is called.
public static void main(String[] args) throws Exception {
// Close all thread except current one
...
// Remaining of my program
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is how I fixed my problem.
First, I interrupt the thread that can be itself interrupted :
In main class (or thread), I detect that my previous thread is not alive anymore and then close the last living thread :
Then in my second thread, that was waiting for a
in.readLine(), I handle it that way, testing in.ready().