简体   繁体   中英

spring async can not add “waitForTasksToCompleteOnShutdown” in <task:executor/>

<task:executor id="ACTIVATION-2000" 
          pool-size="#[ACTIVATION_THREAD_NUMBER]" 
          queue-capacity="20000" 
          waitForTasksToCompleteOnShutdown="true"/>

In an example as above when i add waitForTasksToCompleteOnShutdown property. I get below error since xsd does not support. Why we can not add waitForTasksToCompleteOnShutdown in above naming.

Attribute waitForTasksToCompleteOnShutdown is not allowed to appear in element task:executor .

Answer

Using BeanPostProcessor with below implementation can fix the problem

@Override
public Object postProcessBeforeInitialization(Object object, String arg1)
        throws BeansException {
    if(object instanceof ThreadPoolTaskScheduler)
        ((ThreadPoolTaskScheduler)object).setWaitForTasksToCompleteOnShutdown(true);
    return object;
}

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