How to delay the execution of a program and specify the delay time for access, such as recording the request after receiving the request, so that subsequent operations can be delayed for one day
If it is a Java Web project, start a Servlet in the background, For example <servlet><servlet-name>servlet的名字</servlet-name><servlet-class>servlet所在的包的路径</servlet-class> <load-on-startup>1</load-on-startup></servlet>
And maintain a thread pool in the background, add requests that need to be delayed to the thread pool, and add a time stamp to each thread for subsequent inspection. The Servlet regularly takes out threads from the thread pool to check whether it should be executed. If If the execution condition is met, it will be executed. If it is not met, the thread will be put back into the thread pool. If it is not a web project, you can use Java's Timer. At the same time, you can maintain a thread pool and use Timer to check regularly.
You can use the scheduling framework quartz
1. Record the data received in the database
2. Under Linux, you can use crond to check scheduled tasks and call the trigger task interface provided by java
3. Add the task to redis and use java for scheduled processing.
Create a thread upon receiving a request and execute it after a fixed delay using the ScheduledThreadPoolExecutor method.
Quartz in SpringMVC can freely configure multiple scheduled tasks
If it is a Java Web project, start a Servlet in the background,
For example
<servlet><servlet-name>servlet的名字</servlet-name><servlet-class>servlet所在的包的路径</servlet-class> <load-on-startup>1</load-on-startup></servlet>
And maintain a thread pool in the background, add requests that need to be delayed to the thread pool, and add a time stamp to each thread for subsequent inspection. The Servlet regularly takes out threads from the thread pool to check whether it should be executed. If If the execution condition is met, it will be executed. If it is not met, the thread will be put back into the thread pool. If it is not a web project, you can use Java's Timer. At the same time, you can maintain a thread pool and use Timer to check regularly.