作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个相当标准的 Spring 3.2 应用程序,其中包含一些任务。在我的 applicationContext.xml 中我有
<task:annotation-driven/>
我在代码中还有一些用 @Scheduled
注释的方法。我想给Spring使用的线程池起一个名字,以简化日志分析。有没有相当简单的方法来做到这一点?谢谢。
更新:工作代码:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="1"/>
<property name="maxPoolSize" value="5"/>
<property name="queueCapacity" value="100"/>
<property name="threadNamePrefix" value="executor-task-"/>
<property name="threadGroupName" value="executor-tasks"/>
</bean>
<bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="5"/>
<property name="threadNamePrefix" value="scheduled-task-"/>
<property name="threadGroupName" value="scheduled-tasks"/>
</bean>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
最佳答案
如果您希望能够指定前缀或组名称,则必须配置 TaskScheduler
(对于 @Scheduled
)或 TaskExecutor
> (对于 @Async
)你自己。如果这样做,您可以设置 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>
关于spring - 设置Spring任务的线程池名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26905871/
我是一名优秀的程序员,十分优秀!