日期:2014-05-16 浏览次数:20746 次
建个类
?
?
/** * Hello world! * */ public class App { public static void main(String[] args) throws InterruptedException { while (1 == 1) { System.out.println(args[0] + " ==================== > time " + System.currentTimeMillis()); Thread.currentThread().sleep(1000); } } }
?
?
打成jar 包, Main-class 是A
?
?
写sheel ?test-java.sh
?
?
#!/bin/bash CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar #export CLASSPATH cd /home/guoba/lib java -classpath $CLASSPATH -jar test.jar a & java -classpath $CLASSPATH -jar test.jar b & wait java -classpath $CLASSPATH -jar test.jar c & java -classpath $CLASSPATH -jar test.jar d &
?
?
执行命令:
?
nohup ./test-java.sh > success.log 2>error.log &
?
这种是后台执行,并把标准输出重定向,关闭终端仍在执行
?
./test-java.sh?
?
输出在当前控制台,关闭该终端时,将退出启动的进程。
?
crontab -e
*/2 * * * * /home/guoba/test/test-java.sh 1>success.log 2>error.log?每两分钟启动一次,关闭终端不影响任务
?
?
?
?
?
java -classpath $CLASSPATH -jar test.jar a &
ps -ef
UID PID PPID C STIME TTY TIME CMD
kill -9 [PID]
java -classpath $CLASSPATH -jar test.jar a &
ps -ef
UID PID PPID C STIME TTY TIME CMD
kill -9 [PID]
java -classpath $CLASSPATH -jar test.jar a &
ps -ef
UID PID PPID C STIME TTY TIME CMD
kill -9 [PID]