I am little bit confused with regards to controller objects. As I know controller are singleton by default. How does singleton works for web application, like in below code if thread 1 execute till line 9 and got empId as 12 and thread 2 takes the control from thread 1 and got empId as 23 and complete execution of whole method and then when again thread 1 execute what will be the value of empId will it be 12 or 23.
And also I have noticed that only one object is created for UserServiceDao class so how threads are managed in spring mvc with each thread having its own instance.
1 public class ActionController {
2
3 @Autowired
4 UserServiceDao userServiceDao;
5
int count = 1;
6
7 @RequestMapping("/dashboard.htm")
8 public ModelAndView dashboard(HttpServletRequest request) {
9 String empId = request.getParameter("empId");
10 UserProfile userProfile = userServiceDao.loadEmpById(empId);
System.out.println(count);
count++;
11 }
12 }
Thread first output: 1;
Thread second output : 2;
Thanks.