使用p:poll完成@Async注释方法时,通知最终用户

时间:2015-06-05 08:18:26

标签: multithreading spring jsf primefaces

当Future方法在基于spring的服务层中使用@Async注释并且在ManagedBean调用的应用程序上下文中使用线程池时,如何使用侦听器进行通知。我已尝试使用p:poll侦听器使用侦听器方法future.isDone(),但效果不是很好,因为它向服务器发出了很多请求。

编辑。 这是一个例子

@ManagedBean
@ViewScoped
public class Controller
{

Future<SomeModel> someFuture;
@ManagedProperty(value = "#{someService}")
private SomeService someService;

private String things;

private SomeModel someModel;

private boolean renderSomeModel;

public void callAsyncMethod()
{
    someFuture = someService.thingsToBeInsered(things);
    //here make the poll in jsf start   
}

public void methodAsyncFinished{
    if(someFuture!=null)
        {
            if(this.someFuture.isDone())
            {
                renderSomeModel = true;
            //here make the poll to stop
            }
        }
}



@Service
public class SomeService 
{

 @Async
 Future<SomeModel> thingsToBeInsered(things)
    {
        //Calling the dao here
    return new AsyncResult<SomeModel>(things);
    }
}

// spring context

<task:annotation-driven executor="taskExecutor" proxy-target-class="true"/>
        <bean id="taskExecutor"
            class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
            <property name="corePoolSize" value="${thread_pool.corePoolSize}" />
            <property name="maxPoolSize" value="${thread_pool.maxPoolSize}" />
            <property name="WaitForTasksToCompleteOnShutdown" value="${thread_pool.waitForTasksToCompleteOnShutdown}" />
        </bean>

JSF

<p:poll autoStart="false" widgetVar="asyncGenPoll" interval="6" listener="#{controller.methodAsyncFinished}" update="resultPanel"/>

0 个答案:

没有答案