I have a application where a thread is listening for TCP connections, and will need to be killed. What is the best way to do this? I know that Thread.stop is deprecated, is interrupting the thread enough?
Share
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.
If you have a reference to a
ServerSocketyou can call itsclose()method. This will cause the Thread waiting onaccept()to throw aSocketException.Note that you probably don’t want to expose a reference to the socket itself; you should probably add a method to your server code named
shutdownServer()or similar which does this itself.