Notify end user when @Async annotated method has completed using p: poll

How to notify the listener when the Future method has finished using @Async annotation in spring service layer and with thread pool in application context called from ManagedBean. I tried p: poll listener using listener future.isDone () method but not very efficient because it makes a lot of requests to the server.

Edit. here is an example

@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"/>

      

+3


source to share





All Articles