日期:2014-05-18 浏览次数:20756 次
public class ServerTest {
public static void main(String[] args) {
Connector connector = new Connector();
connector.run();
connector.shutdown();
}
private static class Connector implements Runnable{
private volatile boolean start = true;
public void run() {
while (start) {
try {
Thread.sleep(100);
System.out.println("Respond to requests.");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public void shutdown () {
this.start = false;
}
}
}
Connector connector = new Connector();
connector.run();
connector.shutdown();
Connector connector = new Connector();
Thread t = new Thread(connector);
t.start();
&