我正在使用带有 weblogic workmanager 的 spring @Async,Spring 版本是 3.2.2
网页.xml:
<resource-ref>
<res-ref-name>ReportWorkmanager</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
weblogic.xml:
<work-manager>
<name>ReportWorkmanager</name>
<fair-share-request-class>
<name>Priority</name>
<fair-share>100</fair-share>
</fair-share-request-class>
<min-threads-constraint>
<name>MinThreadCount</name>
<count>15</count>
</min-threads-constraint>
<max-threads-constraint>
<name>MaxThreadCount</name>
<count>25</count>
</max-threads-constraint>
<work-manager-shutdown-trigger>
<max-stuck-thread-time>120</max-stuck-thread-time>
<stuck-thread-count>25</stuck-thread-count>
</work-manager-shutdown-trigger>
</work-manager>
弹簧配置 xml:
<bean id="reportWorkManagerTaskExecutor"
class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="java:comp/env/ReportWorkmanager" />
</bean>
控制器 :
@RequestMapping(value = "/publish", method = RequestMethod.POST)
public MarketingScenario publishReport(@RequestBody final PublishReportDTO reportDTO, final HttpServletRequest request) throws Exception {
reportDTO.setReqUserName(DominoWebUtil.getLoggedInUserName(request));
reportEngine.publishReport(reportDTO);
MarketingScenario scenario = scenarioService.findMarketingScenarioById(reportDTO.getScenarioId());
_LOGGER.debug("Job submitted , successfully came out for scenario id {}", reportDTO.getScenarioId());
return scenario;
}
服务 :
@Async(value = "reportWorkManagerTaskExecutor")
public void publishReport(final PublishReportDTO reportDTO) {
//Some long run job
}
每当请求来自前端时,控制器应该通过调用服务方法来启动工作,它应该返回响应而不等待服务工作。
当@Async 没有被应用时,一切都很顺利,但是当我应用时,服务线程被杀死,因为我的请求线程已经完成。
请让我知道,使用 @Async 如何创建独立于请求线程的线程。
该独立线程可能会运行 2 分钟或 20 分钟,具体取决于输入。