aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How does container handle multiple requests in real time....I know basics but need more info Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How does container handle multiple requests in real time....I know basics but need more info" Watch "How does container handle multiple requests in real time....I know basics but need more info" New topic
Author

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

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
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?


Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
thanks Pedro...your answer as well as link are helpful....
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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

Joined: Jul 11, 2010
Posts: 247

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.


SCJP 6 [SCJP - Old is Gold]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How does container handle multiple requests in real time....I know basics but need more info