Server program considerations

Source: Internet
Author: User

1. Memory leakage may easily occur in server programs. And memory overflow.

These problems often cause the program to fail to run normally, such as abnormal exit and blocking. However, these errors are often confusing because they are hard to be found. Solving these problems often takes a lot of time. Therefore, maintaining good code habits is of great significance to the robustness of a program and also the qualities that a good programmer should possess.

2. server programs are usually deployed on UNIX and other servers and require long-term operation.

In this case, debugging is inconvenient in many cases. Therefore, retaining logs will be of great help to our later debugging. We recommend a very practical log processing interface Apache log4j (official homepage and configuration details ).

So what are the points in the program worth outputting logs?

A. Where the program throws exceptions easily. This allows us to track the location where the program throws an exception and the content of the exception thrown by the program.

B. In a judgment statement. Some logic errors and program errors often occur after the judgment statement. Therefore, log output helps us understand program execution.

C. in a loop. Loops are simple and prone to mistakes. There are many causes for endless program loops. Log output makes it easy for us to determine whether an endless loop exists and to understand program execution.

D. where the file is operated. File Operations are involved in many applications. Especially in the network environment, coupled with personal code habits, file operations are prone to runtime errors. Therefore, it is necessary to check the execution of files to understand file operations.

E. Where the thread is used. A thread must be enabled or disabled. Using logs to output the usage of threads is also important for detecting whether the program runs normally and exits.

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.