Server e thread
In my application i would create a multithread server.
When i launch the server, it listens on a port (with accept method) and i must manage it from consolle.
While it manages the connection in by client, i must can controll the server from the consolle, such as see how many connections are opened, how long time it's running, and stop it.
So, i launch the accept method in a thread.
When i would stop the server, how i can stop the accept method in the other thread?
# 1
I do not quite understand your problem, but perhaps that this will help:
I am guessing that you want to stop a thread. An easy way to do this is to have a boolean variable in a thread, and have the thread check that boolean value for each loop iteration. If the boolean is false, the thread will stop.
class CustomThread extends Thread {
private boolean stopped;
public void run() {
while (!stopped) {
//code, such as accept();
}
//stopped == true
//clean up resources
}
public void end() {
stopped = true;
}
}
//external code in another class
CustomThread t = new CustomThread();
t.start(); //start the thread
//later on....
t.end();
//t will end running shortly.
RATiXa at 2007-7-12 19:33:37 >
