Wildfly 8.2上的Spring异步任务

时间:2014-12-15 04:21:41

标签: spring wildfly-8

我试图使用@Async在我的服务上实现异步方法并返回ListenableFuture,并且返回@ResponseBody Callable的控制器方法,我有一个线程池作为bean配置为Spring的异步支持。它在Tomcat 8.0.15上像魅力一样运行,在Wildfly上,服务方法在控制器方法上执行,但控制器永远不会在容器刚返回的网页上返回"服务不可用" 。我试图删除" ee" Jboss结构部署描述符的模块,但是没有部署WAR。任何人都有一些提示,使这项工作?

修改

记录不要输出任何错误。

控制器:

@RequestMapping(value = {"search/{query}"}, method = RequestMethod.GET)
    public Callable<GithubResult> printResult(@PathVariable String query) {
        Assert.notNull(query, "Query must be not null");
        ListenableFuture<ResponseEntity<GithubResult>> result = githubLookupService.lookup(query);
        return () -> result.get().getBody();
    }

服务:

    @Async
    @Override
    public ListenableFuture<ResponseEntity<GithubResult>> lookup(String query) {
        Assert.notNull(query,"Query must be not null");
        String url = String.format("https://api.github.com/search/repositories?q=%s+language:java", query);
        ListenableFuture<ResponseEntity<GithubResult>> reponseFuture = asyncTemplate
                .getForEntity(url, GithubResult.class);
        try {
            return new AsyncResult<>(reponseFuture.get());
        } catch (InterruptedException | ExecutionException  e) {
            log.error("Cannot retrieve the response entitiy");
            return reponseFuture;
        }
    }

Spring配置:

<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<task:scheduler id="scheduler" pool-size="10"/>
<task:annotation-driven executor="taskExecutor" scheduler="scheduler" proxy-target-class="true"/>

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="50"/>
    <property name="maxPoolSize" value="50"/>
    <property name="queueCapacity" value="20"/>
    <property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>

<bean id="schedulerFacotryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="autoStartup" value="true"/>
    <property name="taskExecutor" ref="taskExecutor"/>
</bean>

0 个答案:

没有答案