I’m writing a chat server in Java. I was using a fixed array of runnable classes where each element in array represents a client. The threads created are in an infinite loop which reads from socket stream.
Now I want to do it with a list so I don’t have to worry about array size and it sounds more legit way of doing it. However I couldn’t be sure if removing an item also terminates the thread. Actually I have no idea what it does. Also, I’m wondering is there any other possible issues with using list in that kind of situaton. Finally, how about array of Timer? Since I’ve used Timer for each client, again, does removing a Timer from a Timer list also stops its schedule? Any possible problems?
Hey there i will refer to this question!
If the thread is started it will not garbage collected as it is referenced by the containing thread.
It will garbage collected if it is done or not started yet!
The reason for this is, when started the thread-object gets added to the current
ThreadGroup(a bit more complex under the hood 🙂 ) and when its done it will automatically removed.