I am making a Skype like program. Say I have 2 calls going that would mean I have 4 threads going. I would have 2 threads that accept the users and then 2 more threads that handle the users messages etc... I made it to where if there is less than 2 users in the call it ends but how do I end one of the accept threads when there are 2 running and how do I tell one of the two to stop. Is there a way that I can use the index number of the thread to stop it?
Asked
Active
Viewed 118 times
-1
-
show what you tried so far – Nicolas Filotto Aug 08 '16 at 18:31
-
2send the recieving thread a signal to end. All your threads are waiting for an input, so send them a message to signal them to end their jobs. As the others say, post your code you have to get into more detail – Henning Luther Aug 08 '16 at 18:33
-
You could make the two threads store the reference of one another and try something like [this](http://stackoverflow.com/questions/3194545/how-to-stop-a-java-thread-gracefully) – Sameer Puri Aug 08 '16 at 18:38
-
Having 4 threads per call is not a great idea in terms of scalability. Java threads are relatively expensive. – Jamie Aug 08 '16 at 19:05
-
Better duplicate is http://stackoverflow.com/questions/4121470/how-to-kill-a-java-thread – Gray Aug 08 '16 at 22:07
1 Answers
1
The correct way is to store your threads in variables (or an array) and to use Interrupts to signal from one thread to another that it should stop. The thread you're signalling to then needs to handle the event.

Daniel Centore
- 3,220
- 1
- 18
- 39