0

in our project, by click a primeFaces command button, a method in a jsf viewScoped bean is called. in this method, a method in a ejb stateless bean is called which in a loop(for loop) execute a query in database. during of run this method in ejb bean, another thread calls the method in the viewScoped bean without any new request and this 2 threads run concurrently. and at end, no results return to client.

commandButton in xhtml form:

<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;
   }
} 

by clicking the command button, testExecute() method is called. and inside it, execute() method is called. during run this method(execute() method), another thread calls the testExecute() method. at end of no thread runs, results show in browser. please help me!

  • is the ejb relevant for the problem? please make a [mcve]... – Kukeltje Jul 15 '17 at 12:30
  • What I mean is the testExecute is called twice and that calls the EJB, so the EJB is not relevant in this problem. Did you compare the stacktraces in the thread so you can maybe trace its origins? – Kukeltje Jul 15 '17 at 13:30
  • @Kukeltje This code is running without any exception. at the end, no result is shown in the browser and the page remains in the same run status – Fahimeh Golzari Jul 16 '17 at 03:31
  • @BalusC I don't undrestand how the linked you mentioned is related to this problem. Could you please explain it? Another issues is that this behavior does not occur constantly. In most cases the scenario works as it's implemented. – Fahimeh Golzari Jul 16 '17 at 05:05
  • in your comment directed at me you repeat what is in your question and in no way answer what requested. Impossible to help then. Good luck – Kukeltje Jul 16 '17 at 06:54

0 Answers0