Sabari
Sabari

Reputation: 73

Will request.getRequestDispatcher().forward creates new thread?

I have a use case that the request to be dispatched by trimming request URL to same context by setting some attributes with it. Will this be handled in same thread or in new thread?

Upvotes: 4

Views: 723

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280102

It will be handled in the same thread. The Servlet specification states

The Container Provider should ensure that the dispatch of the request to a target servlet occurs in the same thread of the same JVM as the original request.

It does seem like this is a recommendation, but most implementations I know of do it in the same thread.

Upvotes: 12

Related Questions