简体   繁体   中英

Task Scheduler in Spring

I am using spring scheduler tasks for calling a method in class after fixed interval like below

<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="processScheduledJobs" method="init" fixed-delay=5000/>

Once the scheduler triggers the init method. init method is going to use the thread pool executor to execute all the jobs in the queue.

<bean id="processScheduledJobs" class="XXXX.VV.ProcessScheduledJobs">
 <property name="pool" ref="jobExecutorService"" />
</bean>

<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  <property name="threadFactory">
      <bean class="XXX..VVV.NamingThreadFactory">
           <constructor-arg value="thread" />
      </bean>
  </property>
  <property name="corePoolSize" value="16" />
  <property name="maxPoolSize" value="64" />
  <property name="keepAliveSeconds" value="4" />
  <property name="queueCapacity" value="512" />
</bean>

Questions: is the initial thread which executed the init method wait till all the processing (done by executor service by spawning new threads) in the init method is finished?

Is the pool size attribute for scheduler task is only used for triggering the tasks not for executing or processing the logic inside the triggered task.

Thread belonging to scheduler will submit all jobs to jobExecutorService . Up to 64 of them will begin executing immediately, the rest, up to 512 will end up in queue. As soon as all are submitted - not executed - the init method will exit. This shouldn't take longer than mere milliseconds.

If scheduler is not the same as jobExecutorService - I can't tell this since part of your xml is missing - its threads won't be used for execution of jobs logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM