L
Louis Cyphre
Hi,
I have a question about the destruction of a Thread in J2ME.
Suppose I have a Thread running a ServerSocket to accept incoming
connections and I have to destroy it at a certain moment.
I can use a boolean variable to stop it as in the code:
public void run() {
/* Creates the ServerSocket */
serverSocket = new ServerSocket( port );
/* Keep accepting connections */
while( !quit ) {
/* Grabs the next incoming connection */
Socket socket = serverSocket.accept();
/* and so on... */
}
}
public void quit() {
quit = true;
}
But... What if the Thread is waiting on the .accept() call?
How can I stop it?
If I cannot stop the Thread during the accept(), can I destroy the
Threaf object? How can I do it?
I have a question about the destruction of a Thread in J2ME.
Suppose I have a Thread running a ServerSocket to accept incoming
connections and I have to destroy it at a certain moment.
I can use a boolean variable to stop it as in the code:
public void run() {
/* Creates the ServerSocket */
serverSocket = new ServerSocket( port );
/* Keep accepting connections */
while( !quit ) {
/* Grabs the next incoming connection */
Socket socket = serverSocket.accept();
/* and so on... */
}
}
public void quit() {
quit = true;
}
But... What if the Thread is waiting on the .accept() call?
How can I stop it?
If I cannot stop the Thread during the accept(), can I destroy the
Threaf object? How can I do it?