how do i kill a particular thread

hello all,

i have developed a streaming audio server;which receives requests for streaming and starts a thread for each request.

the problem is that after i added the "stop" feature on the client;i send a message to the server to stop the streaming.if 2 or more threads are running then all of them are stopped.i do not want this to happen.i want only the specific thread to get killed.help me.

thanks in advance

[437 byte] By [varun_tayura] at [2007-11-27 2:43:56]
# 1
How is stop currently implemented on the server?
developer_jbsa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 2

> How is stop currently implemented on the server?

the client sends a code "0#" in the UDP packet to the server;this is checked in the "run()" method of the server's thread's.actually the problem i am facing is how to identify the thread to stop and after identification; stop only that thread.

varun_tayura at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 3

you could have your server keep track of its clients' sessions (by ip:port) and corresponding worker threads, maybe a HashMap (ip:port)=>Thread

when a stop message is received by server, the client's ip:port could be used to get the server's worker thread and call the appropriate thread's stop

developer_jbsa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 4

Surely you should just despatch that packet to the appropriate client thread, just like any other packet from that client, and have the client thread perform its own exit? You can't just stop a thread from outside, i.e. without its co-operation.

And you shouldn't have anything in the server run() loop that interprets data - that's a job for client threads. The less the run() method does, the faster it will go.

ejpa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 5

assumptions

there is 1 server

there are n clients

there is 1 server port handling client requests

with these assumptions it seems some sort of server-side map is needed to track which client corresponds to the appropriate server thread. The server would have to resolve which thread to stop, then set the appropriate thread's stop flag, no static (shared) flag

developer_jbsa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 6
Why can't the client thread receive the stop packet and stop itself?
ejpa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...
# 7
Replacing my asumption 3 with: client is multicasting requests to server> client thread receive the stop packet and stop itself?sounds appropriate
developer_jbsa at 2007-7-12 3:10:02 > top of Java-index,Core,Core APIs...