Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does container handle multiple requests in real time....I know basics but need more info

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say we have a server running on a machine, say a CPU.

Now on that server, lets say my application is running. I know that my container will handle multiple clients.I mean using multiple threads for every request. But afterall , CPU can run only one thread at a particular time ..right? so wont other threads wait and wont the users see delay?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can ask yourself the very same question: how can you load a page and listen a music in the same time? Or how can you play games (video, music, key strokes actions, mouse position recognition)?
How does the CPU let you do few things in the same time and still you can't see the delay?
And what about people in only-single-CPU times? How did they work... :-)

Simplifying the whole thing - the CPU is basically using a round-robin scheduling which gives each thread a slice of time to act, then the thread is moving out (CPU changes the context) and another thread goes in action. Then it's moved out, another goes on and so on.

This question is not related to the Servlet, EJB or any other container but rather to OS/CPU scheduling basics.

If this doesn't answer your question, maybe these resources do:
http://en.wikipedia.org/wiki/Round-robin_scheduling
http://en.wikipedia.org/wiki/Scheduling_algorithm

HTH!

Cheers!
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Pedro...your answer as well as link are helpful....
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.

Oh and I did forgot to add that the round-robin uses slices so small that user basically can't tell the difference and, in the same time, it gives a feeling that multiple threads can run in the same time. So it's basically "cheating" the user to make an impression that it all happens in the same moment.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seconding Pedro Kowalski's points,

Adding some more info,

Container implicitly uses Thread Pool exclusively to handle requests... So its not like for each request , a new thread will be created.. If its, it ends up in out of memory issue...

Container re-uses the threads in thread pool to handle the requests.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic