0
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

        //some code here
        
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

        //performTask(req, resp);
        //some code here
        }
    
private void insertRequestTemplate() {
HttpSession session = req.getSession();
responsePage = req.getParameter("ResponsePage");
ServletContext ctx = getServletConfig().getServletContext();
ctx.getRequestDispatcher(responsePage).forward(req,resp);
readMessage();

public void readMessage()
    {
        System.out.println("calling MessageTrigger_ABean");
        MessageTrigger_ABean msg = new MessageTrigger_ABean();
        msg.read();
    }

msg.read() has the code to read messages from MQ. Inside insertRequestTemplate method, I am calling readMessage method after ctx.getRequestDispatcher(responsePage).forward(req,resp);is this the correct way of calling this? But inside insertRequestTemplate method, the page is not getting forwarded to the next page untill readMessage() is executed because of which the page keeps on loading for a long time until message is read from MQ. Could you please help me on this.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
C2D
  • 29
  • 1
  • 6

1 Answers1

0

Most examples I have seen of a servlet forwarding the request to another servlet have the dispatcher forward invocation at the end of the method. ie. there is no more code, other than closing braces at the end of the method.

I am guessing that the forwarding doesn't happen until the invoking method completes. So where you have your msg.read() will stop the insertRequestTemplate method from completing. This will more than likely be because the code inside msg.read is being performed synchronously. Leading to http timeouts on the http request.

How you solve this will depend on what you want to do with the messages you obtain from msg.read().

chughts
  • 4,210
  • 2
  • 14
  • 27
  • using msg.read() I am processing these messages and updating status of request. What can be the solution for this. – C2D Sep 15 '20 at 11:53