1
public ActionForward doSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

     //Logging
     System.out.println("Inside doSearch for job | Date: " + new Date());

     //doing search operation
     listJobCard = getDaoFactory(request).getJobCardDAO(comLocator).findAllByJobSearch(jobSearch);

     request.getSession().setAttribute("listJobCard", listJobCard);

     System.out.println("Exiting doSearch for job | Date: " + new Date());

     return mapping.getInputForward();
}

I have put System.out.prinln(); for logging at the beginning and at the end of this method just to know the flow of threads. And the outcome is synchronised, the method executed one after another. The output is below.

Inside doSearch for job | Date: Sat Jan 28 14:52:39 IST 2017

Exiting doSearch for job | Date: Sat Jan 28 14:52:50 IST 2017

Inside doSearch for job | Date: Sat Jan 28 14:52:50 IST 2017

Exiting doSearch for job | Date: Sat Jan 28 14:53:00 IST 2017

  • I am calling this action method from two different browsers and it gets executed one after another(When first one complete then the second one starts its execution). I am using struts1.3. – Amrinder Kalsi Jan 27 '17 at 21:01
  • I have not used any Synchronization here, then why its behaving like this? – Amrinder Kalsi Jan 27 '17 at 21:02
  • Struts 1 uses the same instance for all requests, but it is invoked concurrently (so it's not thread safe). How are you determining it's sequential instead of concurrent invocations? – Andrew S Jan 27 '17 at 22:08
  • Thanks @Andrew S for your response. I have amended the method and using the logging to verify the thread's execution. Please see the outcome above. The method executed sequentially instead of concurrently. – Amrinder Kalsi Jan 28 '17 at 09:33
  • There could be any number of reasons you're seeing this behavior. It's impossible to know with the information provided. – Dave Newton Feb 01 '17 at 12:15
  • Thanks Dave Newton for your response. Could you please elaborate what could be the reasons for this and what further information is required? – Amrinder Kalsi Feb 01 '17 at 18:21

0 Answers0