LinuxIn the systemJavaPrograms are executed independently, rather than in the web Container environment. At this time, many container resources cannot be directly obtained, such as the data source configured in the database connection pool, and third-party jar packages required for program running.
In this case, you need to set environment variables, such as java paths and classpath environment variables. Special processing is required for data source configuration, such as data source configuration files, log configuration files, and resource file loading, example:
#!/bin/bashtempClassPath=$CLASSPATH;flist=/home/smsdp/SohuMbRegist/lib/*.jar;for i in $flist;domypath=$i;CLASSPATH=$CLASSPATH:$mypath;doneCLASSPATH=$CLASSPATH:$tempClassPath;export CLASSPATHexport JAVA_HOME=/usr/local/javacd /home/smsdp/SohuMbRegist/classesnohup $JAVA_HOME/bin/java com.sohu.zxl.ivr.JobService & >/dev/null
The above code is a shell script file:
1. First, declare two variables. tempClassPath is the current environment variable $ CLASSPATH, and flist is a directory file array which can be considered as an array );
2. splice the jar path and assign the value to the current $ CLASSPATH environment variable;
3. Set environment variables;
4. Go to the class directory;
5. Execute the program and output it to the nohup. out Virtual File.
After the independent java program is executed, the thread is automatically destroyed. You can run the command ps-ef | grep JobService to find the thread ID during program execution, the thread cannot be found after the thread is searched.
You can set the program execution time and frequency through scheduled job and crontab .......... of course, the execution time frequency can also be controlled in the java program, but the crontab control is more flexible. We recommend that you use crontab to control the execution time that changes frequently.