File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request Dispatch Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request Dispatch Problem" Watch "Request Dispatch Problem" New topic
Author

Request Dispatch Problem

singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
can someone expalin this ...

SRV1.8.2
"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"

regards
-santosh
Frederic Esnault
Ranch Hand

Joined: Feb 13, 2006
Posts: 284
Just imagine that you use your RequestDispatcher to include a servlet (for a forward this is not so clear). You have some variables, some kind of state that you want to find again when you come back from the include call.

But a servlet instance is part of a thread, and only one thread access a servlet at once. So if a dispatch is made in another thread, the coming back could come in another thread, which means you could loose your previous state.

For this (and other reasons probably), a dispatch should be made in the same thread.

Is it clear?


SCJP 5 - SCWCD 1.4 - SCBCD 1.3 - Certification study documents/resources: http://esnault.frederic.free.fr/certification
singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
hi fedric,
thanks for ur reply..
But i have a question ,since for each request container forks a thread from a servlet instance(not taking SingleThread Model into cosideration) which serves the request .But how can a request meant for thread (Lets say A) be dispatched from another thread (B)

I mean if i have to diapcatch(include) a request from A->C then how it is possible to do same(for the same request) from B->C unless u do somthing like A->B then B->C.

regards
-santosh
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
from a servlet instance(...) which serves the request .But how can a request meant for thread (Lets say A) be dispatched from another thread (B)


It is not dispatched to other threads, that's the point.

Your container creates a ServletRequest instance when it receives an HTTP request from outside, then forks a new thread (or picks one from a pool or whatever) and then runs the service(...) of the Servlet instance with this ServletRequest instance (and ServletResponse) using the thread it just picked. Then, if you never fork the thread yourself, the container guaranties than whenever you forward/include the request, all the processing will happen in the same thread, that is, sequencially : you never have the servlet where you forwarded/included your request run in parallel of you current request.


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
 
jQuery in Action, 2nd edition
 
subject: Request Dispatch Problem