SFTP file monitoring and early warning method and device, equipment, storage medium and product
By loading scheduled task information from the database and using the ThreadPoolTaskScheduler thread pool and jsch to connect to the SFTP server, the problem of complex SFTP file monitoring and warning configurations and security vulnerabilities in the existing technology is solved, achieving simple configuration and high stability, and ensuring a multi-threaded environment. concurrency safety.
Patent Information
- Application Number
- CN202410912449.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-10-18
AI Technical Summary
The existing technology requires a lot of code work and configuration when implementing SFTP file monitoring and warning, and has security loopholes. It cannot meet the needs of simple configuration and use, especially in multi-threaded environments, where there are concurrency security issues.
By loading scheduled task information from the database, using ConcurrentHashMap to store the task object, and putting it into the ThreadPoolTaskScheduler thread pool, connecting to the SFTP server through jsch to determine whether the task meets the monitoring standards based on preset rules, realizing periodic execution and monitoring of tasks, ensuring Concurrency safety in multi-threaded environments.
It realizes the simple configuration and use of SFTP file monitoring and warning, ensures system stability and concurrency security, avoids potential thread safety issues, supports dynamic modification of task information and takes effect immediately, and is suitable for distributed deployment environments.
Smart Images

Figure CN118796469A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an SFTP file monitoring and early warning method, device, equipment, storage medium and product. Background Art
[0002] With the development of computer technology, the amount of business data involved in resource management systems has increased exponentially, and the business interactions between the system and the outside world have become increasingly frequent. Among these data interaction methods, direct acquisition methods that regularly generate SFTP files and push them to the peer end or regularly pull files from the peer end account for a considerable proportion.
[0003] In the current business interaction mode between various systems, the regularly generated SFTP files are usually pushed to the peer end, or the peer end regularly pulls files for direct acquisition to determine whether the SFTP files at this time meet the corresponding requirements, and then executes related alarms or compensation operations logically according to the results of this task.
[0004] However, in order to achieve this purpose, the method in the background technology requires a lot of code work and a huge configuration workload, and there are security vulnerabilities, which cannot meet the needs of simple configuration and use.
[0005] For example, the crontab command that comes with the Linux machine can be used to set the quality of periodic execution for subsequent file reading and execution. However, this method requires configuring crontab commands one by one, which makes the configuration workload huge. Another method is to use the lightweight distributed task scheduling platform XXL-JOB for task scheduling, but this method requires a lot of code work and has security vulnerabilities. Summary of the invention
[0006] The present invention provides an SFTP file monitoring and early warning method, device, equipment, storage medium and product, which are used to solve the defects in the prior art and realize the simple configuration and use of SFTP file monitoring and early warning.
[0007] The invention provides an SFTP file monitoring and early warning method, comprising: loading scheduled task information from a database to obtain a task object; storing the task object in a ConcurrentHashMap; when a task starts, the task object is placed in a ThreadPoolTaskScheduler thread pool, and an execution cycle is set by calling a schedule method; executing the task according to the execution cycle, with at most only one task being executed at the same time; connecting to an SFTP server through jsch, judging whether the task meets a monitoring standard according to a preset rule, and obtaining a monitoring result.
[0008] According to the present invention, an SFTP file monitoring and early warning method also includes: responding to the operation of creating a new scheduled task, checking the parameters of the newly created scheduled task; obtaining a new task object according to the task information that passes the check; saving the new task object to a database and a ConcurrentHashMap; and putting the new task object into a ThreadPoolTaskScheduler thread pool to make the newly created scheduled task effective.
[0009] According to an SFTP file monitoring and early warning method provided by the present invention, the method further includes: in response to an operation of deleting a scheduled task, finding a task object of the scheduled task to be deleted from a ConcurrentHashMap; calling a cancel method through the task object of the scheduled task to be deleted to cancel the scheduled task to be deleted from the ThreadPoolTaskScheduler thread pool.
[0010] According to an SFTP file monitoring and early warning method provided by the present invention, the method further includes: in response to an operation of modifying a scheduled task, finding a task object of the scheduled task to be modified from a ConcurrentHashMap; calling a cancel method through the task object of the scheduled task to be modified to cancel the scheduled task to be modified from a ThreadPoolTaskScheduler thread pool; determining parameters of the scheduled task to be modified and performing parameter verification; obtaining a modified task object of the scheduled task according to task information that passes the verification; saving the modified task object of the scheduled task to a database and a ConcurrentHashMap; and putting the modified task object of the scheduled task into a ThreadPoolTaskScheduler thread pool to make the modified scheduled task effective.
[0011] According to an SFTP file monitoring and early warning method provided by the present invention, scheduled task information is loaded from a database to obtain a task object; the task object is stored in a ConcurrentHashMap, including: abstracting each task into a task object that implements the Runnable interface; and storing the task object in the ConcurrentHashMap as a global variable.
[0012] According to an SFTP file monitoring and early warning method provided by the present invention, whether a task meets the monitoring standard is judged according to a preset rule to obtain a monitoring result, including: judging whether the task meets the monitoring standard according to the preset rule to obtain a monitoring result; the monitoring result includes unqualified files that do not meet the monitoring standard; summarizing the unqualified files to obtain early warning data; and giving a prompt according to the early warning data.
[0013] The present invention also provides an SFTP file monitoring and early warning device, comprising: a loading module, used for loading scheduled task information from a database to obtain a task object; the task object is stored in a ConcurrentHashMap; a cycle setting module, used for when a task starts, the task object is placed in a ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling a schedule method; an execution module, used for executing tasks according to the execution cycle, with at most only one task being executed at the same time; a monitoring module, used for connecting to an SFTP server via jsch, judging whether a task meets a monitoring standard according to preset rules, and obtaining a monitoring result.
[0014] The present invention also provides an electronic device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned SFTP file monitoring and early warning methods is implemented.
[0015] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the SFTP file monitoring and early warning method as described above is implemented.
[0016] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned SFTP file monitoring and early warning methods.
[0017] The SFTP file monitoring and early warning method, device, equipment, storage medium and product provided by the present invention include: loading scheduled task information from a database to obtain a task object; storing the task object in a ConcurrentHashMap; when a task starts, the task object is placed in a ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling a schedule method; executing the task according to the execution cycle, with at most only one task being executed at the same time; connecting to an SFTP server through jsch, judging whether the task meets the monitoring standard according to preset rules, and obtaining a monitoring result. Through the above-mentioned method, the present invention has a simple configuration and strong system stability; it ensures concurrent security in a multi-threaded environment and avoids potential thread safety issues. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 The present invention is a flowchart of an SFTP file monitoring and early warning method provided by an embodiment of the present invention.
[0020] Figure 2 The present invention provides a system framework flow chart of the SFTP file monitoring and early warning method.
[0021] Figure 3 It is a structural diagram of an SFTP file monitoring and early warning device provided by an embodiment of the present invention.
[0022] Figure 4 It is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiment of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0025] It should be noted that all actions of acquiring signals, information or data in the present invention are performed in compliance with the corresponding data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.
[0026] The core idea of SFTP file monitoring in related technologies is to configure scheduled tasks to trigger monitoring of custom rules, determine whether the SFTP file at this time meets the corresponding requirements, and then logically execute relevant alarms or compensation operations based on the results of this task. The specific examples are shown below: 1. Linux machine's built-in crontab
[0027] The crontab command in Linux is used to set instructions to be executed periodically. The command reads instructions from the standard input device and stores them in the "crontab" file for later reading and execution. The cron system scheduling process can be used to run jobs during non-peak load periods every day, or at different times of the week or month. Cron is the main scheduling process of the system and can run jobs without human intervention. The crontab command allows users to submit, edit or delete corresponding jobs. Each user can have a crontab file to save scheduling information. System administrators can prohibit or allow through the two files cron.deny and cron.allow.
[0028] For example, save the monitoring script in the corresponding path in advance and name it monitor.sh, then save the following command to call the sh script every weekday at 11:59 pm.
[0029] Disadvantages: The resource management system involves very complex business, and the workload of using crontab to configure one by one is very huge, which is not suitable for businesses with large business volume and certain logic. (For example, the file path is dynamic and generated according to the abbreviation of the time of the day.)
[0030] 2. Use xxl-job
[0031] XXL-JOB is a lightweight distributed task scheduling platform with good performance and UI interface support. It can reduce the difficulty of use and is user-friendly. However, this framework is not applicable to resource management systems for the following reasons: 1. When adding a new task, you need to create a new class in the background project, and then associate the task with the class. You need to do code work every time, which is not friendly to non-developers.
[0032] 2. The XXL-JOB version may have security vulnerabilities, and frequent upgrades will affect the stability of the system.
[0033] Based on this, the present invention provides an SFTP file monitoring and early warning method, which can prevent multiple servers from executing tasks simultaneously and causing errors in a distributed deployment, and can be easily configured and used by non-R&D personnel.
[0034] See also Figure 1 , Figure 1 1 is a flow chart of an SFTP file monitoring and early warning method provided in an embodiment of the present invention. In this embodiment, the SFTP file monitoring and early warning method may include steps S110 to S140, and each step is specifically as follows.
[0035] S110: Loading scheduled task information from the database to obtain a task object; the task object is stored in a ConcurrentHashMap.
[0036] S120: When the task starts, the task object is placed in the ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling the schedule method.
[0037] S130: Execute tasks according to the execution cycle, with at most only one task being executed at the same time.
[0038] S140: Connect to the SFTP server through jsch, determine whether the task meets the monitoring standard according to the preset rules, and obtain the monitoring result.
[0039] Optionally, the scheduled task information is loaded from the database to obtain the task object; the task object is stored in the ConcurrentHashMap, including: abstracting each task into a task object that implements the Runnable interface; the task object is stored in the ConcurrentHashMap as a global variable.
[0040] Optionally, whether the task meets the monitoring standards is determined according to preset rules to obtain monitoring results, including: determining whether the task meets the monitoring standards according to preset rules to obtain monitoring results; the monitoring results include unqualified files that do not meet the monitoring standards; summarizing the unqualified files to obtain early warning data; and providing prompts based on the early warning data.
[0041] Under the condition of meeting certain requirements, the stability of the system is inversely proportional to the complexity, and the simpler the system, the stronger its robustness. Therefore, this embodiment is directly transformed based on the tools provided by Java.
[0042] The transformation core of this embodiment is the ThreadPoolTaskScheduler thread pool in Java technology, which is a task scheduler in the Spring framework and provides thread pool-based task scheduling and execution functions.
[0043] At the same time, this embodiment sets a Java built-in ConcurrentHashMap for high concurrency to store task objects and scheduling results, ensuring concurrency safety in a multi-threaded environment and avoiding potential thread safety issues.
[0044] Finally, this embodiment can use the Redisson framework to implement distributed locks, and through lock competition, it is achieved that the execution of tasks will not be triggered multiple times at the same time under distributed deployment, that is, at most only one task is executed at the same time.
[0045] When the underlying framework of the resource management system is developed based on Java, the deployment method of springcloud is adopted, so some scheduled task methods that come with Java can be used. Another method provided in the relevant technology is to use the functions that come with Java to implement scheduled tasks, but if it modifies specific information, it must wait until the next task is completed before it takes effect. For example: 1. Timer class: Use the schedule() or scheduleAtFixedRate() method of the Timer class to set a scheduled task, but this method is outdated and is not recommended.
[0046] 2. Use @Scheduled annotation: For example, write an annotation on the required method to represent the call of the method. Similar to crontab, its biggest disadvantage is that the monitoring time cannot be changed dynamically. After modifying the time, the project must be restarted, otherwise it will not take effect.
[0047] 3. Implement the SchedulingConfigurer interface, rewrite the configureTasks method, extract the public monitoring method in an abstract way, save the SFTP files that need to be monitored in the database through a unified template, load all tasks when the project starts, and then start the scheduled tasks according to the rewritten logic, which can save a lot of work efficiency. However, there is a fatal disadvantage that when modifying the monitoring information, it must wait until the next task is completed before it takes effect.
[0048] The solution provided by the embodiment of the present invention, by using native Java underlying technology, can not only solve the above-mentioned problems, but also support dynamic modification of monitoring information. The modified information can take effect immediately without introducing additional third-party dependencies. In a distributed deployment, it can prevent multiple servers from executing tasks at the same time and causing errors, and non-R&D personnel can also easily configure and use it.
[0049] In some embodiments, it also includes: in response to the operation of creating a new scheduled task, checking the parameters of the newly created scheduled task; obtaining a new task object based on the task information that passes the check; saving the new task object to the database and ConcurrentHashMap; and placing the new task object into the ThreadPoolTaskScheduler thread pool to make the newly created scheduled task effective.
[0050] In some embodiments, it also includes: in response to the operation of deleting the scheduled task, finding the task object of the scheduled task to be deleted from the ConcurrentHashMap; calling the cancel method through the task object of the scheduled task to be deleted to cancel the scheduled task to be deleted from the ThreadPoolTaskScheduler thread pool.
[0051] In some embodiments, it also includes: in response to the operation of modifying the scheduled task, finding the task object of the scheduled task to be modified from the ConcurrentHashMap; calling the cancel method through the task object of the scheduled task to be modified to cancel the scheduled task to be modified from the ThreadPoolTaskScheduler thread pool; determining the parameters of the scheduled task to be modified and performing parameter verification; obtaining the task object of the modified scheduled task based on the task information that passes the verification; saving the task object of the modified scheduled task to the database and ConcurrentHashMap; putting the task object of the modified scheduled task into the ThreadPoolTaskScheduler thread pool to make the modified scheduled task effective.
[0052] See also Figure 2 , Figure 2 The present invention provides a system framework flow chart of the SFTP file monitoring and early warning method.
[0053] The whole process can be divided into the following steps: 1. When the project is first started, all scheduled task information will be loaded from the corresponding database, and each task will be abstracted into a task object (the task object must implement the Runnable interface and override the run method. In fact, the run method is the specific method of business monitoring, which varies from person to person). The primary key or other unique key of the information in the database is used as the key, and the task object is stored as a value in ConcurrentHashMap as a global variable, which provides an entry for modification if necessary.
[0054] 2. When starting a task, the task object will be thrown into the ThreadPoolTaskScheduler thread pool by the system. The scheduler provides a rich API interface that can not only modify the number of core threads, but also select the queue type and discard strategy, etc., and can achieve customized development. After receiving the task object, the scheduler will start calling the schedule method and assign the execution cycle of the object to the task. After the trigger time, the system will send a request to redis and compete with other machines for the redis lock. Since redis is deployed on a single machine and in a single process state, only one request will occupy the lock at the same time, and then start executing the custom configured SFTP monitoring task to ensure uniqueness.
[0055] 3. After connecting to the corresponding SFTP server through jsch, the task is judged according to the rules whether it meets the monitoring standards. For example, whether the file is generated on time, whether the file format is legal, whether certain fields of the file meet the requirements of the other end, etc. Unqualified files will be summarized and notified to the corresponding resource person in charge by email or SMS to reduce the loss of the other end system.
[0056] 4. After startup, after creating a new scheduled task, it can still be made effective immediately. The principle is that the system will first do some basic parameter verification. After passing the verification, it will be stored in the database and the primary key id will be recorded at this time. Then the id will be used as the primary key, and the task object will be stored as the value in ConcurrentHashMap. Finally, the task will be thrown into the ThreadPoolTaskScheduler thread pool to complete the new function that takes effect in real time. Similarly, when a task needs to be deleted, the system will first match the task with the corresponding key value from ConcurrentHashMap. Since the task implements the Runnable interface, ThreadPoolTaskScheduler will return the ScheduledFuture object. You can directly call its cancel method to cancel the task from the thread pool, and finally delete it from the ConcurrentHashMap and database table in turn. The same operation is used for the requirements that need to be modified to take effect, but after the cancel method, the database is first updated, and then it is re-registered in the Map as with the new addition.
[0057] Compared with using crontab, the embodiment of the present invention has significantly lower workload and is more applicable in slightly complex business situations; compared with other methods that use java itself, firstly, the task can be changed dynamically without restarting the service; secondly, there is no need to wait for the next task to be completed after modifying the task interval, and it has extremely high real-time performance; finally, it supports the use of redis locks in distributed deployment to ensure the uniqueness of tasks and avoid data errors caused by simultaneous execution; compared with XXL-JOB, it is more suitable for a wider range of people, without touching the back-end code, only needing to configure the corresponding rules on the interface to run, and non-R&D personnel can also master it proficiently. The embodiment of the present invention is completely based on the java language, has natural affinity, does not need to reference other three-party dependencies, and has stronger system stability.
[0058] The present invention further provides an SFTP file monitoring and early warning device. The SFTP file monitoring and early warning device provided by the present invention is described below. The SFTP file monitoring and early warning device described below and the SFTP file monitoring and early warning method described above can be referred to each other.
[0059] See also Figure 3 , Figure 3 Schematic diagram of the structure of the SFTP file monitoring and early warning device provided by the embodiment of the present invention. In this embodiment, the SFTP file monitoring and early warning device may include
[0060] The loading module 310 is used to load the scheduled task information from the database to obtain the task object; the task object is stored in the ConcurrentHashMap.
[0061] The cycle setting module 320 is used to set the execution cycle by calling the schedule method when the task starts. The task object is placed in the ThreadPoolTaskScheduler thread pool.
[0062] The execution module 330 is used to execute tasks according to an execution cycle, and at most only one task is executed at the same time.
[0063] The monitoring module 340 is used to connect to the SFTP server through jsch, determine whether the task meets the monitoring standard according to the preset rules, and obtain the monitoring result.
[0064] In some embodiments, the SFTP file monitoring and early warning device also includes a new scheduled task module, which can be specifically used to: respond to the operation of creating a new scheduled task, verify the parameters of the new scheduled task line; obtain a new task object based on the task information that passes the verification; save the new task object to the database and ConcurrentHashMap; put the new task object into the ThreadPoolTaskScheduler thread pool to make the new scheduled task effective.
[0065] In some embodiments, the SFTP file monitoring and early warning device also includes a scheduled task deletion module, which can be specifically used to: in response to the operation of deleting a scheduled task, find the task object of the scheduled task to be deleted from the ConcurrentHashMap; call the cancel method through the task object of the scheduled task to be deleted to cancel the scheduled task to be deleted from the ThreadPoolTaskScheduler thread pool.
[0066] In some embodiments, the SFTP file monitoring and early warning device also includes a scheduled task modification module, which can be specifically used for: in response to the operation of modifying the scheduled task, finding the task object of the scheduled task to be modified from the ConcurrentHashMap; calling the cancel method through the task object of the scheduled task to be modified to cancel the scheduled task to be modified from the ThreadPoolTaskScheduler thread pool; determining the parameters of the scheduled task to be modified and performing parameter verification; obtaining the modified task object of the scheduled task based on the task information that has passed the verification; saving the modified task object of the scheduled task to the database and ConcurrentHashMap; and putting the modified task object of the scheduled task into the ThreadPoolTaskScheduler thread pool to make the modified scheduled task effective.
[0067] In some embodiments, the loading module 310 can be specifically used to: abstract each task into a task object that implements the Runnable interface; and store the task object in a ConcurrentHashMap as a global variable.
[0068] In some embodiments, the monitoring module 340 can be specifically used to: determine whether the task meets the monitoring standards according to preset rules to obtain monitoring results; the monitoring results include unqualified files that do not meet the monitoring standards; summarize the unqualified files to obtain warning data; and provide prompts based on the warning data.
[0069] The SFTP file monitoring and early warning device provided by the embodiment of the present invention includes: a loading module, which is used to load the scheduled task information from the database to obtain the task object; the task object is stored in the ConcurrentHashMap; a cycle setting module, which is used to put the task object into the ThreadPoolTaskScheduler thread pool when the task starts, and set the execution cycle by calling the schedule method; an execution module, which is used to execute the task according to the execution cycle, and at most only one task is executed at the same time; a monitoring module, which is used to connect to the SFTP server through jsch, and judge whether the task meets the monitoring standard according to the preset rules to obtain the monitoring result. Through the above method, the present invention has a simple configuration and strong system stability; it ensures the concurrent security in a multi-threaded environment and avoids potential thread safety issues.
[0070] On the other hand, an embodiment of the present invention further provides an electronic device, see Figure 4 , Figure 4 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention, such as Figure 4 As shown, the electronic device may include: the electronic device may include a memory 420, a processor 410, and a computer program stored in the memory 420 and executable on the processor 410. When the processor 410 executes the program, the SFTP file monitoring and early warning methods provided by the above methods are implemented.
[0071] Optionally, the electronic device may further include a communication bus 430 and a communication interface (CommunicationsInterface) 440, wherein the processor 410, the communication interface 440, and the memory 420 communicate with each other via the communication bus 430. The processor 410 may call a computer program in the memory 420 to execute the SFTP file monitoring and early warning method, which may include: Load the scheduled task information from the database to obtain the task object; store the task object in ConcurrentHashMap; when the task starts, the task object is placed in the ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling the schedule method; execute the task according to the execution cycle, and at most only one task is executed at the same time; connect to the SFTP server through jsch, determine whether the task meets the monitoring standards according to the preset rules, and obtain the monitoring results.
[0072] In addition, the logic instructions in the above-mentioned memory 420 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0073] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the SFTP file monitoring and early warning method provided by the above methods. Its steps and principles have been introduced in detail in the above methods and will not be repeated here.
[0074] On the other hand, the present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the SFTP file monitoring and early warning method provided by the above methods. Its steps and principles have been introduced in detail in the above methods and will not be repeated here.
[0075] Non-transitory computer-readable storage media can be any available media or data storage devices that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO)), optical storage (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drives (SSDs)), etc.
[0076] In summary, the SFTP file monitoring and early warning method, device, equipment, storage medium and product provided by the present invention include: loading the scheduled task information from the database to obtain the task object; the task object is stored in the ConcurrentHashMap; when the task starts, the task object is placed in the ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling the schedule method; the task is executed according to the execution cycle, and at most only one task is executed at the same time; the SFTP server is connected through jsch, and the task is judged according to the preset rules whether it meets the monitoring standard to obtain the monitoring result. Through the above method, the present invention has a simple configuration and strong system stability; it ensures the concurrent security in a multi-threaded environment and avoids potential thread safety issues.
[0077] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0078] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A SFTP file monitoring and early warning method, characterized in that: include: Load scheduled task information from the database and obtain the task object; The task object is stored in ConcurrentHashMap; When the task starts, the task object is placed in the ThreadPoolTaskScheduler thread pool, and the execution cycle is set by calling the schedule method; Execute tasks according to the execution cycle, with at most one task being executed at the same time; Connect to the SFTP server through jsch, determine whether the task meets the monitoring standards according to the preset rules, and obtain the monitoring results.
2. The SFTP file monitoring and early warning method according to claim 1 is characterized in that: Also includes: In response to the operation of creating a new scheduled task, parameter verification is performed according to the newly created scheduled task; Obtain a new task object according to the verified task information; save the new task object to the database and ConcurrentHashMap; Put the new task object into the ThreadPoolTaskScheduler thread pool to make the newly created scheduled task effective.
3. The SFTP file monitoring and early warning method according to claim 1 is characterized in that: Also includes: In response to the operation of deleting the scheduled task, find the task object of the scheduled task to be deleted from ConcurrentHashMap; The cancel method is called through the task object of the scheduled task to be deleted to cancel the scheduled task to be deleted from the ThreadPoolTaskScheduler thread pool.
4. The SFTP file monitoring and early warning method according to claim 1 is characterized in that: Also includes: In response to the operation of modifying the scheduled task, find the task object of the scheduled task to be modified from ConcurrentHashMap; Call the cancel method through the task object of the scheduled task to be modified to cancel the scheduled task to be modified from the ThreadPoolTaskScheduler thread pool; Determine the parameters of the scheduled task to be modified and perform parameter verification; Obtaining a modified task object of the scheduled task according to the verified task information; saving the modified task object of the scheduled task to the database and ConcurrentHashMap; Put the task object of the modified scheduled task into the ThreadPoolTaskScheduler thread pool to make the modified scheduled task effective.
5. The SFTP file monitoring and early warning method according to claim 1 is characterized in that: The scheduled task information is loaded from the database to obtain the task object; The task object is stored in ConcurrentHashMap, including: Abstract each task into a task object that implements the Runnable interface; The task object is stored in ConcurrentHashMap as a global variable.
6. The SFTP file monitoring and early warning method according to any one of claims 1 to 5, characterized in that: The step of determining whether the task meets the monitoring standard according to the preset rules and obtaining the monitoring result includes: Determine whether the task meets the monitoring standard according to the preset rules, and obtain the monitoring result; the monitoring result includes unqualified files that do not meet the monitoring standard; Summarize the unqualified documents to obtain early warning data; Prompt according to the early warning data.
7. An SFTP file monitoring and early warning device, characterized in that: include: Loading module, used to load scheduled task information from the database and obtain task objects; The task object is stored in ConcurrentHashMap; The cycle setting module is used when the task starts. The task object is placed in the ThreadPoolTaskScheduler thread pool and the execution cycle is set by calling the schedule method. An execution module, used for executing tasks according to the execution cycle, with at most only one task being executed at the same time; The monitoring module is used to connect to the SFTP server through jsch, determine whether the task meets the monitoring standards according to the preset rules, and obtain the monitoring results.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the SFTP file monitoring and early warning method as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the SFTP file monitoring and early warning method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the SFTP file monitoring and early warning method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Scheduling method of timing task and scheduling server
CN107797859A
Timed task control method and device for dynamically adding and deleting and storage medium
CN117112175A
