I want a commandButton
to call a method in my managed bean that will process something asynchronously (new Thread
) then the request should complete immediately without waiting the new Thread
to finish. I want this async code to execute for as long it needs, independent of the user session.
But the request doesn't complete and keeps waiting the Thread to finish, I don't understand why. Did I get something wrong here?
xhtml:
<p:commandButton
value="Update"
id="updateButtonId"
styleClass="internalButton"
action="#{myBean.processUpdate}"
onstart="PF('loading').show()"
oncomplete="PF('loading').hide()"
update="myDataTableId" />
Bean:
@ManagedBean(name="myBean")
@ViewScoped
public class MyBean {
...
public void processUpdate(){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//do something...
}
});
thread.start();
}
}