在我们的项目中,通过单击primeFaces命令按钮,调用jsf viewScoped bean中的方法。在此方法中,调用ejb无状态bean中的方法,该方法在循环(for循环)中执行数据库中的查询。在ejb bean中运行此方法期间,另一个线程在没有任何新请求的情况下调用viewScoped bean中的方法,并且这两个线程并发运行。最后,没有结果返回给客户。
以xhtml形式的commandButton:
<p:commandButton id="btnTestExecute"
value="run"
actionListener="#{drawingEditBean.testExecute()}"
process="@all"
update=":mainForm"
ajax="true"
icon="fa fa-trophy"
oncomplete="blinkNextButton()"/>
jsf bean:
public abstract class DrawingBean implements BaseBean {
private List<DrawingWinnerDto> testResult;
@EJB
private DrawingService drawingService;
@PostConstruct
@Override
public void init() {....}
public void testExecute() throws Exception {
LOG.debug("testExecute started");
testResult = drawingService.execute(drawingHeaderDto.getId());
LOG.debug("testExecute finished");
}
}
@Named
@ViewScoped
public class DrawingEditBean extends DrawingBean {
public static String PAGE_TITLE = "DrawingEdit";
public String getPageTitle() {
return PAGE_TITLE;
}
}
ejb bean:
@Stateless
public class DrawingService {
public List<DrawingWinnerDto> execute(Long drawingId) throws Exception {
Drawing drawingEntity = entityManager.find(Drawing.class, drawingId);
List<DrawingWinnerDto> retValue = new ArrayList<>();
Query queryAlgorithm2Core = entityManager.createNamedQuery("DrawingService.Drawing_Algorithm2_Core");
queryAlgorithm2Core.setParameter("drawing_id", drawingEntity.getId());
queryAlgorithm2Core.setParameter("winner_list", new LargeList("Number_List", winnerCandidates));
for (Reward reward : drawingEntity.getRewards()) {
for (int i = 0; i < reward.getQuantity(); i++) {
Object[] result = (Object[]) queryAlgorithm2Core.getSingleResult();
.....
}
}
return retValue;
}
}
单击命令按钮,调用testExecute()方法。在其中,调用execute()方法。在运行此方法(execute()方法)期间,另一个线程调用testExecute()方法。在没有线程运行结束时,结果显示在浏览器中。 请帮帮我!