• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Request Dispatch Problem

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic