As a Java program ape, "communicating needs", "designing databases", "building tables" and "coding development" are common things. We have to do such work repeatedly almost every day, and some even enjoy it! (of course, if the money is in place ~ ~); But if you want to ask them what they are very sensitive to, or even occasionally disgusted with, it is undoubtedly bugs and some difficult and miscellaneous diseases! How to quickly locate, troubleshoot and diagnose the corresponding bugs and solve the corresponding difficult and miscellaneous diseases in the online production environment has become a topic worthy of discussion. Without more words, let's go directly to the text!!!
Without detours, let's say the answer first: with the help of Alibaba's open source Java diagnostic tool Arthas, you can quickly and intuitively locate, troubleshoot and diagnose bugs in the production environment;
At this time, a little friend may ask, what is this guy? How can I quickly locate, troubleshoot and diagnose bugs in the production environment? How is it used in the actual production environment? Can you do something practical
Don't worry, let's talk about debug... Let's talk about what Arthas is first:
This guy is "Alibaba's open source online diagnostic tool for Java applications, which is deeply loved by developers". This is the official definition of Arthas, enenen... It's too short... Forget it, the avenue is simple, which does not affect debug's love for it. Interested partners can click its open source address:
- https://github.com/alibaba/arthas/blob/master/README_CN.md
- arthas: Arthas is Alibaba's open source Java diagnostic tool
Note: some small partners may not be able to access github. It doesn't matter. Click the (2) link, which is the address of the corresponding code cloud specifically found by debug for everyone;
Next, let's take a look at what problems Arthas can solve? Just look at the introduction on the official website:
There is no doubt that this is a powerful and easy-to-use online diagnostic tool. If it is used well, it can eliminate many difficult and miscellaneous problems of online production environment, especially in the mode of separate development and deployment of front and rear ends, such as It is a piece of cake for Arthas to quickly locate the parameters passed by the front end, view the results returned by the interface, view the method path executed by the interface and its corresponding time-consuming, and monitor the occupation of memory / CPU and other indicators of the whole Java application
So how to use it in the actual production environment? Let's be practical:
(1) Here, we take the interface of the course center of the "programmer combat base fightjava.com" deployed in the Linux environment as an example to learn and practice the use of Arthas in the actual production environment; The fully qualified class name of the method of this interface is:
com.debug.coding.fight.server.controller.web.IndexCourseController.center()
The corresponding complete code is as follows:
@RestController public class IndexCourseController extends IndexWebAbstractController{ private static final Logger log= LoggerFactory.getLogger(IndexCourseController.class); //Home course Center @RequestMapping(value = prefix + "/center", method = RequestMethod.GET) public BaseResponse center(@Validated IndexCourseQuery query, BindingResult result){ if (result.hasErrors() || query.getPageNo() <= 0 || query.getPageSize() <= 0) { return new BaseResponse(StatusCode.InvalidParams); } BaseResponse response = new BaseResponse(StatusCode.Success); try { //indexCourseService.indexCourseCenter(query) is the code logic to be executed response.setData(indexCourseService.indexCourseCenter(query)); } catch (Exception e) { return new BaseResponse(StatusCode.Fail.getCode(), e.getMessage()); } return response; } }
The request parameter of this method is IndexCourseQuery, which is defined as follows:
@Data @ToString public class IndexCourseQuery implements Serializable { @NotNull private Integer pageNo=1; @NotNull private Integer pageSize=Constant.COURSE_CENTER_PAGE_SIZE; private String search; private Integer typeId; }
The response result is stuffed into the BaseResponse class. The result is returned by the indexCourseService service class calling the indexCourseCenter() method. The type is: Map < string, Object >. There are many core data in it. It will not be posted here. Everyone can access it Programmer combat base Then, click the course center and F12 to see the response result returned after the request interface link:
(2) OK, after so much introduction, some partners may wonder "what does this have to do with Arthas?" to be honest, it really does, because debug will take this plate and interface as an example to view the resource allocation of the whole Java application, the input parameters of interface calls, and the results returned by the interface based on the Linux environment The path of the interface method call and its corresponding time consumption.......... then go directly!
For more information, see: http://www.mark-to-win.com/tutorial/51078.html