Home  >  Q&A  >  body text

java random delayed execution

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

某草草某草草2702 days ago876

reply all(5)I'll reply

  • 巴扎黑

    巴扎黑2017-05-27 17:42:47

    You can use the scheduling framework quartz

    reply
    0
  • 为情所困

    为情所困2017-05-27 17:42:47

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-27 17:42:47

    Create a thread upon receiving a request and execute it after a fixed delay using the ScheduledThreadPoolExecutor method.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:42:47

    Quartz in SpringMVC can freely configure multiple scheduled tasks

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-27 17:42:47

    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.

    reply
    0
  • Cancelreply