search

Home  >  Q&A  >  body text

java - scheduleWithFixedDelay() 和 scheduleFixedRate() 区别

ScheduledExecutorService类 scheduleWithFixedDelay() 和 scheduleFixedRate() 区别

迷茫迷茫2854 days ago939

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:36:05

    I guess what you want to say is the scheduleAtFixedRate method

    1. scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)
      We can use this method to delay the execution of tasks and set the execution cycle of the task. The time period is calculated from the thread that first starts executing in the thread pool, so assuming that the period is 1s and the thread executes for 5s, the next thread will be executed soon after the first thread finishes running.

    2. scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)
      This method can be used to delay periodic execution of tasks. delaytime is the delay time between the thread stopping execution and the next start of execution. Assume the following code

    reply
    0
  • Cancelreply