if i have a simple servlet that has a doGet() that simple creates a Date object and then outputs the date to the screen, and say it is accessed by 10 people using their web browsers
1) are 10 servlet instances created? or is just one servlet instance created, and doGet() is executed 10 times, and so each time it is executed, then a Date object is created?
2) how long will the servlet instance stay created for?
3) how long will the date instances stay created for?
If the request is for a servlet, load the servlet class and invoke its service method, passing the ServletRequest and ServletResponse objects. Note that in this servlet container, the servlet class is loaded every time the servlet is requested.
what does the servlet class is loaded means? That a new instance is created for the servlet? If so, the above is saying that each time a request happens, a new instance of the servlet is created, surely that is wrong, yes?
I can't access the link you've specified. But this is what normally happens
Unless explicitly made to implement the SingleThredModel interface, every servlet has only one instance created. The init method is called once. Every time a new request is made to the servlet, a new thread is created and the service method is called. Thus the service method is called multiple times for the same servlet instance. Thus, in your case, a new date instance would be created every time the service request is called (or rather the doGet is called). If it's called once by 10 users or 10 times by one user, as long as it's a new request, a new instance will be created.
Finally when the servlet is destroyed, the destroy method is called - once for the servlet instance (which is just one in our case).
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD