Results 1 to 4 of 4
- 12-17-2009, 04:03 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
How do I stop or kill a running thread when a condition is true
I have a class ImpServer which has a method accept, which a client can call by Remote Method Invocation. Accept method has an inner class which implements runnable. I try to use return to exit from the run method if nm is equal to userName. But there is no exit from the run method. What I actually want to do is to stop the thread from running. I don't no how to do this. Please somebody help me
public class ImpServer extends UnicastRemoteObject implements ExchangeContract, Runnable{
public void accept(final String nm) throws RemoteException {
new Thread(new Runnable() {
public void run() {
synchronized(client){
for(int i=0; i<client.size(); i++){
String userName = (String)client.get(i);
if(nm.equals(userName)){
try{
cc.notifyDuplicateName("Duplicate names”)
}catch(Exception e){}
return;
}
}
}
try {
synchronized(client) {
client.add(nm);
send(nm);
ss = new Sub(nm);
sData.add(ss);
}
} catch(Exception e) {
System.err.println(e);
}
}
}).start();
}
}
- 12-17-2009, 04:05 PM #2
Member
- Join Date
- Dec 2009
- Location
- Rio de Janeiro
- Posts
- 38
- Rep Power
- 0
You need to keep a reference to the thread. Try "interrupt" method, then.
Please don't laugh at my English... I'm trying my best! :)
- 12-17-2009, 04:19 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
could u please give me a code example
- 12-21-2009, 11:07 PM #4
Similar Threads
-
kill a thread
By Peter in forum Advanced JavaReplies: 6Last Post: 06-22-2010, 08:08 AM -
How to stop Thread
By ersachinjain in forum Threads and SynchronizationReplies: 2Last Post: 11-30-2009, 07:11 PM -
Thread won't stop
By bubbless in forum Threads and SynchronizationReplies: 15Last Post: 10-20-2009, 10:58 PM -
How to stop/pause running third party exe?
By 2bGeek in forum AWT / SwingReplies: 3Last Post: 02-28-2009, 07:26 AM -
how to stop a thread
By willemjav in forum Advanced JavaReplies: 19Last Post: 09-10-2008, 07:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks