Is this code threadsafe? Static method modifying http servlet request

I've a class with a static method which takes two parameters- HttpServletRequest request and HttpServletResponse response :

public class RequestProcessor {
    public static processRequest(HttpServletRequest request, HttpServletResponse response) {
    //read request and write data to response
    }
}

Several threads can be calling RequestProcessor.processRequest method at same time.

After doing some research, my understanding is that since stacks are local to threads so it shouldn't be a problem but I am not sure if this code is still thread safe because HttpServletRequest request and HttpServletResponse response are not immutable

Jon Skeet
people
quotationmark

Yes, that should be absolutely fine, so long as the method isn't using/modifying any shared mutable state, and you only call it within normal servlet processing - so each thread that calls it will be passing in the request/response that it's currently handling.

(If multiple threads start modifying the same request/response, that would certainly cause problems.)

people

See more on this question at Stackoverflow