it should look like the following.
Allowing for the thread acsessing the hashtable extracting the
referenenced Thread object and calling Thread.interupt() , which BTW
sets *INTERRUPTED* flag in the Thread object,
The use of the an instance variable is redundant since the thread already has
a flag designed for that perpose.
Example :
<<< some other thread code >>>>
Thread t = htbl.get("XXXXX");
t.interrupt();
>>>>>>>>>>>>>>>>>>>>>>>>>>
class xxxxx extends Thread {
void run() {
try{
while(true){
if(interrupted()){
// do all your clean up here
return;
}
// do something else here
}
}
catch( InterruptedException e){
e.printStactTrace();
return;
}
}
Cheers
Chris
Christopher Hinds wrote:
I am assuming you are using jdk1.2 and in that case the stop method has been
depricated. You should use use Thread interrupt to stop the thread.
When you remove the Thread object from the hashtable issue a Thread.interrup()
call so the thread object unwinds correctly and exits the run method then set the obejct reference to null so on the next GC pass the dead thread object will be garbage collected.
Example:
class xxxxxx implements Runnable {
// class code here
void run() {
try {
while(true) {
// some code here
}
}
catch(InterruptedException e) {
e.printStackTrace();
return;
}
}
}
}
Cheers
Chris
yangyuex wrote:
Hi I have several threads in one hashtable. When I remove one of them, whether this thread still consume CPU etc resources? That's to say, if I will not need one thread, whether I must stop or destory it explictly or just remove it from hashtable for garbage collection? I am not sure how JVM schedules multiple threads.Thanks very much! yangyuexiang ---------------------------------------------------------------------- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]