Author of ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- OCPJP Online Training -- Twitter -- How to Ask a Question
soven rout wrote: How to implement singleton concept in servlet?
soven rout wrote: How to implement singleton concept in servlet?
SCJP5
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
How to implement singleton concept in servlet?
SCJP 5, SCWCD 5
Prabhakar Reddy Bokka wrote:
How to implement singleton concept in servlet?
It is not singleton servlet but a single threaded servlet we can create by implementing a marker interface 'SingleThreadModel'.
But this is deprecated in JavaEE 5.
Palak Mathur wrote:
Prabhakar Reddy Bokka wrote:
How to implement singleton concept in servlet?
It is not singleton servlet but a single threaded servlet we can create by implementing a marker interface 'SingleThreadModel'.
But this is deprecated in JavaEE 5.
Will SingleThreadModel internally be using singleton pattern?
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Tim Holloway wrote:
Palak Mathur wrote:
Prabhakar Reddy Bokka wrote:
How to implement singleton concept in servlet?
It is not singleton servlet but a single threaded servlet we can create by implementing a marker interface 'SingleThreadModel'.
But this is deprecated in JavaEE 5.
Will SingleThreadModel internally be using singleton pattern?
Not literally. What it does is it instructs the container not to schedule more than one thread to use the servlet at a time. Until the first thread returns, no other thread may be invoked on it.
Piyush Mangal wrote:There can only be a single instance of a servlet at any given point of time. All concurrent requests are processed by a sever by having multiple threads executing on a single instance of a servlet. So in a way, your servlet is already singleton.
Palak Mathur wrote:
Piyush Mangal wrote:There can only be a single instance of a servlet at any given point of time. All concurrent requests are processed by a sever by having multiple threads executing on a single instance of a servlet. So in a way, your servlet is already singleton.
Are you sure? Is it multiple thread on single instance or the servlet container creates a pool of instances for a servlet to handle concurrent responses?
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
SCJP5
suppose if any websites (web application which is hosted in internet) and if it gets multiple requests at a time will the container creates multiple instances to the servlet component ?(if that web applcaition is developed using servlets as web resource program
). for example just assume xxx bank site getting lots of requests at a time..?
Piyush Mangal wrote:
suppose if any websites (web application which is hosted in internet) and if it gets multiple requests at a time will the container creates multiple instances to the servlet component ?(if that web applcaition is developed using servlets as web resource program
). for example just assume xxx bank site getting lots of requests at a time..?
That is where clustering and load balancing comes into picture. You deploy multiple instances of web server and load balancer manages the load by dispatching the request to the appropriate server.
Even databases are also clustered to achieve the desired scalability.
SCJP5
A servlet is not a "program". It is a component of a deployed Web Application that presents a service method, which (usually) routes an incoming URL request to a secondary method such as doGet() or doPost().
The servlet operates when the container obtains a thread from the container's Thread Pool and runs it with a request to invoke the servlet's service() method. So, yes, servlets must be thread-safe as must any code that they invoke.
Being "thread-safe", however, does not give one license to lock the servlet for long periods of time, nor may the servlet spawn secondary threads for long-running tasks. There are tricks to managing such things, but explaining them is for another time.
Piyush Mangal wrote:
suppose if any websites (web application which is hosted in internet) and if it gets multiple requests at a time will the container creates multiple instances to the servlet component ?(if that web applcaition is developed using servlets as web resource program
). for example just assume xxx bank site getting lots of requests at a time..?
That is where clustering and load balancing comes into picture. You deploy multiple instances of web server and load balancer manages the load by dispatching the request to the appropriate server.
Even databases are also clustered to achieve the desired scalability.
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|