本人写了一个类:
public class Stake {
    public static void main(String[] args) throws SQLException, IOException,
            ClassNotFoundException, IllegalAccessException,
            InstantiationException, InterruptedException {
        try {
            //连接数据库 ....
           //无限循环,读取某个表中的值,当值为1时,结束一个进程,然后重新启动他
            while(1==1){
            if (stake.equalsIgnoreCase("1")) {
                    Runtime rt = Runtime.getRuntime();
                    Process proc = rt.exec("/home/test/restart.sh");
            }
            Thread.sleep(15000);
         }       }
}restart.sh内容如下:
cd /home/zh008
now_pid=`ps -u zh008|grep java|awk '{print $1}'`
kill $now_pid
nohup ./smsp &restart.sh文件执行没问题,但是当执行完毕都,循环就结束了,不知是什么原因,我想让他一直循环!

解决方案 »

  1.   

    try {
                //连接数据库 ....
               //无限循环,读取某个表中的值,当值为1时,结束一个进程,然后重新启动他
                while(1==1){
                if (stake.equalsIgnoreCase("1")) {
                        Runtime rt = Runtime.getRuntime();
                        Process proc = rt.exec("/home/test/restart.sh");
                }
                Thread.sleep(15000);
             }
    ----------
    按你的描述似乎要吧while语句写在try的前面才由可能循环读取数据库的某个值啊