I have a thread:
Thread t = new Thread(){
public void run(){
ServerSocketConnection scn = (ServerSocketConnection)
Connector.open("socket://:1234");
// Wait for a connection.
SocketConnection sc = (SocketConnection) scn.acceptAndOpen();
//do other operation
}
};
t.start();
Lets say no client is connecting to the Server, so this thread will be blocked.Now I want to kill the above thread t? How can I kill it?
Thread.interrupt()will not interrupt a thread blocked on a socket. You can try to callThread.stop()orThread.destroy(), but these methods are deprecated (edit: actually, absent in J2ME) and in some cases non-functional, for reasons you can read about here. As that article mentions, the best solution in your case is to close the socket that you’re blocking on: