Suppose I have one repeated task which is going to process HttpSession or HttpServletRequest or HttpServletResponse object. This processing may be abstract some data from HttpSession or set/get some attributes in HttpServletRequest/HttpServletResponse.
Here I am giving one example for idea. I want my current logged in UserId from session. for that I am making one Util method in one of Util classes.
public static Integer getCurrentLoggedInUserId(HttpSession session)
{
// here I will process session object and get first User object and
//after that I will get id from that User Object. This is one repeated task in my app.
}
second example for download file.
public static void downloadFile(HttpSrvletResponse response)
{
// here I will set some attribues/parameters in response for download file.
}
Now my question is it thread safety to doing this? I mean is it recommended to pass session/request/response objects from controller/servlets to Util classes? If not, what is solution for these kind of repeated tasks?
Thanks in advance.