In general, a Java background application, in the Linux terminal can start multiple, which causes waste of resources, and even the mutual operation of competing resources cause problems. The application is also launched using shell script, and there are some limitations in the shell script. You can skillfully avoid the problem of repetitive startup.
For example, the application directory structure is:
app
bin(存放启动脚本startup.sh和class文件、配置文件等。)
lib(存放引用的库)
Suppose the application class name is: Mypack. Myappmain
startup.sh
#!/bin/sh
programdir= "."
program= "Mypack. Myappmain the
num=$#
temp= $CLASSPATH
#setting libs path
libs= ... /lib/*
Append () {
temp= $temp ":"
}
for file in $libs; Do
Append $file
Done
Export classpath= $temp:.:.. /: $programdir
Export LANG=ZH_CN
res= ' ps aux|grep java|grep $program |grep-v Grep|awk ' {print $} '
If [-N ' $r Es "]
then
Echo" Myappmain already running "
Else
Nohup java- Classpath $CLASSPATH Mypack. Myappmain
Sleep 3
unset res
res= ' PS aux|grep java|g Rep $program |grep-v Grep|awk ' {print $} '
If [-N ' $res]
then
echo "Myappmain start Success"
Else
Echo MyApp Main start Error "
Fi
Fi
"/p>
You can then use this script to start up and solve the problem.
Attention:
There may also be a problem with startup.sh not executing permissions at startup, to 777.
You may also receive an error message:
: bad interpreter: 没有那个文件或目录
This is because the startup.sh script encoding is not correct, you need to ensure that the document format is UNIX, this problem many people have stumbled, I am no exception, that the shell script syntax is not correct, in fact, is the problem of file encoding!
The following is a script that does not have a limited recurring startup problem:
#!/bin/sh
programdir="."
num=$#
temp=$CLASSPATH
#setting libs path
libs=../lib/*
append(){
temp=$temp":"$1
}
for file in $libs; do
append $file
done
export CLASSPATH=$temp:.:../:$programdir
export LANG=zh_CN
nohup java -classpath $CLASSPATH mypack.MyAppMain &
Source: http://lavasoft.blog.51cto.com/62575/243360