• Post Reply Bookmark Topic Watch Topic
  • New Topic

thread is equal to session

 
jacob deiter
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
servlet is multithreaded ,multithread means when many users access the same servlet then it will be multi threaded,each thread will serve single user.
when many users access a web application,session will be created for each users,

then Can I say that each thread is equal to session.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jacob,

you shouldn't make too many assumptions on how a servlet container may handle user requests. Usually each user request is handled by a different thread to be able to handle as many users as the hardware allows. But this doesn't mean that there has to be a one-to-one mapping between users and threads. This is simply an implementation detail of the container and you shouldn't build your application on these assumptions.

The only thing you should really take care of is that a servlet may be accessed simultaneously by more than one threads and therefore servlets in general have to be thread-safe!

Marco
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider that a single user can send more than one request at a time (eg multiple tabs). They need different threads but share the same session, so no you cannot say that.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additionally I should have mentioned that a bunch of servlet containers in a clustered environment may allow session migrating to another node. If a session migrates to another node a totally different host may server subsequent requests of the same session which are definitely handled by another thread - even another JVM.

Marco
[ September 24, 2008: Message edited by: Marco Ehrentreich ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
Consider that a single user can send more than one request at a time (eg multiple tabs). They need different threads but share the same session, so no you cannot say that.


GOOD EXPLANATIONS
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!