我有如下一段代码,在运行java -jar e:\test.jar start后程序开始运行,我现在想要程序退出,我该怎么做?public class ThreadTest extends Thread {
/**
* @param args
* @throws dException
*/
private static int i = 0; public static void main(String[] args) throws Exception {
if (args != null && args.length>0) {
String arg = args[0];
if (arg.equals("start")) {
while (true) {
System.out.println("==================" + i);
i++;
sleep(5 * 1000);
}
}else if(arg.equals("quit")){
System.exit(0);
}else{
System.exit(0);
}
} else {
System.exit(0);
}
}}
/**
* @param args
* @throws dException
*/
private static int i = 0; public static void main(String[] args) throws Exception {
if (args != null && args.length>0) {
String arg = args[0];
if (arg.equals("start")) {
while (true) {
System.out.println("==================" + i);
i++;
sleep(5 * 1000);
}
}else if(arg.equals("quit")){
System.exit(0);
}else{
System.exit(0);
}
} else {
System.exit(0);
}
}}
解决方案 »
- 求解。。IO系统不解之1
- J2SE遇到瓶颈了,求大侠帮助
- 重新认识netbeans
- 用JAVA语言想写一个类似飞鸽传书的软件,可是一旦开启防火墙,便无法传送文件,用户列表也是时隐时现其他用户,请问怎样传透防火墙呢?
- 怎么让JAVA的JtextField获得光标时,输入法为日文平假名
- 界面切换问题
- 奇怪!!!!!HttpServletRequest的getInputStream()方法?????
- SQL语句不能正确执行,高分求助
- 启用 java控制台调试Applet问题(在线等)
- 关于在linux下用java操作数据库的问题,急!!1
- 求教有关Runtime问题
- 谁有在线中文版Java API帮助文档java类软件包手册?
System.out.println("==================" + i);
i++;
sleep(5 * 1000);
}
你这循环里没有判断退出条件,怎么出?
if (args != null && args.length>0) {
boolean flag = false;
String arg = args[0];
if (arg.equals("start")) {
flag = true;
while (flag ) {
System.out.println("==================" + i);
i++;
sleep(5 * 1000);
}
}else if(arg.equals("quit")){
System.exit(0);
}else{
System.exit(0);
}
} else {
System.exit(0);
}
}
这段代码不是死循环,是进入else块里