I am now working in a medium-sized Internet enterprise, the salary and treatment of the job at the end of last year is very good, but summed up to say that the beautiful is the hope of the whole village, it is not good to hear that a person almost did a project team. Here is one of my project fire fighting experiences (back pot experience). Is the year after a cooperative company on-line a sub-business system, docking the company's internal single-point system. I received the company's technical advice: After the start of the project is not regularly suddenly unable to login, after restarting, login after a time and can not log in again, the other technician confused do not know what the reason, the background log does not have any error message. I stepped, rushed to the project to work on fire, in fact, the original 2 days can solve the problem, let me spend 5 days to solve. I have one by one explanations for specific reasons.
1, not mastering the essence of log logs
Log log debug,info,error Information disorderly Dozen, the use of debug with info, the use of info with the debug ..., the result is a login successful request, the background log hit 300 lines of code, seriously affect the efficiency of troubleshooting tracking problems, The log level on the project line is still the debug level, changing to the info level, and the result is that a lot of key information is not printed.
The key information of the log output format is not perfect, the log is in what kind of name, the thread that occurs, and the number of lines in the code is not clearly displayed, where the log is printed is unknown.
About here, I want to say is, will be more framework, SPARK,FLINK,HADOOP, message middleware and other upper frame configuration in the slip is just huaquanxiutui, log log is the internal strength, it is in the future to face a variety of online problems can quickly troubleshoot a means.
The following is his log output:
2, core parameters do not judge
The data returned by the method does not make null or "" string judgments, resulting in various cases of NULL pointer exceptions. The function of the project is idealized, I think I need this data to give you the correct results, otherwise I do not know where the error. This problem caused me to restore the scene of the case caused me a great deal of confusion, a lack of attention to a null pointer error, I have to strengthen the judgment of this error processing, so that I can simulate the number of logons after multiple login.
In addition, the use of SQL statements in the project is not standardized, combined with the preceding null to determine that no, there is a: "Ah, I use this account login success, SQL is correct, with this person's account login, how to report SQL syntax is not correct ah, obviously called the same block code AH"
It is obvious that the syntax of this SQL statement is roleid by the "' ' String.
3, local variable promoted to static variable
This is the reason for the question at the beginning of the article, because the login is to authenticate the user to a single point system, so it uses the HttpClient framework to send the HTTP request, where it takes the httpclient variable as a static variable and then re-uses the object in the method. Then the method inside called the object and did not release the resource reasonable close, the framework will maintain a connection pool by default, if you request a resource is not released after use, then the resource will not be used by the next request, the new request must wait in the queue, and then when the user logs 20 times, The requests in the resource pool are exhausted, and the new request is not waiting for the resource to wait in the queue, causing the server to time out and the logon failure 504 error.
If you want to learn Java engineering, high performance and distributed, in Layman's. Micro-service, Spring,mybatis,netty source analysis of friends can add my Java Advanced Group: 582505643, the group has Ali Daniel Live interpretation technology, as well as Java large-scale Internet technology video free to share to everyone.
At that time, I saw this class of static variables when the httpclient, my heart floated a bad feeling, here is an error prone place, if it is me, to this framework, this class is not fully grasp, I will it into a local variable, so in low concurrency, let the GC to help me recycle it.
After transformation:
4, Interceptor Path planning confusion
This problem also caused me to troubleshoot the problem, to troubleshoot the login problem, I first want it to log on after the success of the back-end path to trace out, to see exactly which part of the code problem, because there is no task error message. What about his interceptor? A login request succeeded the interceptor repeatedly executed three times, in the middle of at least one interceptor is not doing any effective out, the problem arises is that his front-end business sends unrelated requests, was intercepted caused by, this forced me to restore the full path through the log insertion pile count to outline it, For me to review the code to find out the opportunity to call httpclient this piece of code question provided.
5, disorderly use try Catch
This is also very disgusting, its code suddenly try catch packing, hey, this guy has a good, but also some unusual marking record, I carefully read the code, this is what ghost ah, catch how to eat the abnormal information, eat and eat, you do not print abnormal information, Do not throws abnormal, so ferocious will be abnormal eating, obviously have problems, it does not report, through it to trigger a new anomaly to the real problem of snow.
Finally, I would like to say that programmers bother programmers, code left a line, in the future to meet what. You do not want to yourself to dig a hole, can not solve, and then come to a "big brother, you busy, I have a small problem, help to see Bai (Kegua zi)."
A five-year Java development career in a spit-out project fire (programmers bother programmers)