Currently, I have a while loop for listening the port. When a socket accepta a connection, a Task, which implements a runnable interface will be created, and is assigned to the LinkedList named o_allTaskThreads to store it. That is to let me have control, to stop them.
s = this.o_ServerSocket.accept();
System.out.println("connection established");
PortListenTask plt = new PortListenTask(s,this.o_config);
this.o_allTaskThreads.add(plt);
plt.run();
But I got some problems here, if the PortListenTask is done/finished or have exception terminaled, it can’t update the linkedLIst o_allTaskThreads, how can I solve it? Thanks.
When the PortListenTask’s run() method ends (normal execution completes), can it not update the linked list (I assume to remove itself) then? If you add a try / catch handler around the contents of your run() method then hopefully you can trap abnormal situations and help guide them through the same clean exit. You should always try and signal a thread to exit itself, rather than abort them externally, to allow such a clean exit.