Independent Java program execution in Linux

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.