为Spring任务设置线程池名称

为Spring任务设置线程池名称,spring,scheduled-tasks,Spring,Scheduled Tasks,我有一个相当标准的Spring3.2应用程序,其中包含一些任务。在我的applicationContext.xml中 <task:annotation-driven/> 如果希望能够指定前缀或组名,则必须为@Scheduled配置TaskScheduler,或为@Async配置TaskExecutor。如果执行此操作,则可以设置threadGroupName和threadNamePrefix属性以自定义线程的名称 <bean id="taskScheduler" class=

我有一个相当标准的Spring3.2应用程序,其中包含一些任务。在我的applicationContext.xml中

<task:annotation-driven/>

如果希望能够指定前缀或组名,则必须为@Scheduled配置TaskScheduler,或为@Async配置TaskExecutor。如果执行此操作,则可以设置threadGroupName和threadNamePrefix属性以自定义线程的名称

<bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
    <property name="corePoolSize" value="2"/>
    <property name="maxPoolSize" value="5"/>
    <property name="queueCapacity" value="25"/>
    <property name="threadNamePrefix" value="scheduled-task"/>
    <property name="threadGroupName" value="scheduled-tasks-tg"/>
</bean>

显式配置允许您设置threadGroupName和threadNamePrefix属性的TaskExecutor。我尝试了以下方法:但无效。请将代码添加到问题中,而不是添加注释。这样它就保持可读性。确保将执行器连接到任务:annotation-driven。在这种情况下,什么不起作用?别觉得奇怪,看起来应该有用。您需要一个TheADPool任务调度程序。。。我的错误。执行器用于@Async而不是@Scheduled。我的应用程序中有多个@Scheduled注释任务。在上述所有任务的方法中,将使用相同的前缀。我更愿意为每个任务提供不同的前缀。可能吗?嗨,曼努:-我有相同的场景,我有多个@Scheduled注释。你能在同一个网站上分享你的经验/解决方案吗
<bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
    <property name="corePoolSize" value="2"/>
    <property name="maxPoolSize" value="5"/>
    <property name="queueCapacity" value="25"/>
    <property name="threadNamePrefix" value="scheduled-task"/>
    <property name="threadGroupName" value="scheduled-tasks-tg"/>
</bean>