Spring scheduled task usage and how to use mail monitoring server
Spring related dependencies can be imported to use spring's scheduled tasks!
Scheduled tasks are commonly used in development, such as order query. A customer orders something that has not been paid, and it will automatically expire after the order aging period. How do you know the timeliness of the order? Scheduled tasks can be queried every minute or every second.
The application of scheduled tasks is very wide. The following applications are monitoring servers. Although there are many open-source monitoring software, such as ZABBIX, Nagios or others. Next, I will monitor the server using code:
First, prepare the mail dependencies:
Mail tool class:
Monitoring server class:
Specific scheduled task classes:
Therefore, the purpose of monitoring the server can be achieved. Of course, this is only a small test, and it is not comprehensive enough. Of course, there are problems. If it is a regular task detection every minute, and suddenly a server hangs up, it will send e-mail continuously. 163 e-mail is limited, and frequently may be regarded as spam. I only need to know one message, So and so server goes down, one time is OK, and finally send it to me 30 times. In this case, a large number of invalid emails are a waste of resources and time. Therefore, this article is just a small example of server monitoring. In actual development, do not use it directly. It is best to have relevant judgment and logic. Only in this way can we be more efficient and meet expectations.