public class Process implements Runnable{
public static void main(String[] args) {
boolean finishFlag = true;
while (finishFlag) {
//do something
}
}
}
因为在主线程中用了while循环,导致无法通过服务管道停止进程,错误代码是这样的:
主线程一直在while循环而无法通过服务停止,正确做法是应该把while循环放在另一个线程中执行,使主线程接收到停止的消息。
public class Process implements Runnable{
public static void main(String[] args) {
Thread thread = new Thread(new Process());//启用另外一个线程来处理业务.否则服务无法进行停止启动操作.
thread.start();
}
public void run() {
boolean finishFlag = true;
while (finishFlag) {
//do something
}
}
}
很低级的错误= =