0

On to the Servlets Application , i know that there is only one Servlet created , which perofrms all requests for the Actions

If we have a DTO Object which we use for Setting the Data inside the Servlet , for example

public class Servlet extends HttpServlet
{

public void doGet()
{

EmployeeDTO edto = new EmployeeDTO();

edto.setName("Test");
}
}

Now if there are 100 reuests , how many DTO objects created here ??

Pawan
  • 31,545
  • 102
  • 256
  • 434

2 Answers2

0

100 of course. You don't want to share request-specific data between individual endusers, do you?

On a related note, it may be helpful to read this to learn more about how exactly servlets work behind the scenes: How do servlets work? Instantiation, sessions, shared variables and multithreading.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Each time a GET request comes to your servlet, the doGet method is called, and the new EmployeeDTO() statement is executed.

So if 100 requests are done, 100 instances of EmployeeDTO are created. When the request ends, unless you have stored the DTO somewhere where it can still be reached, the DTO is eligible to garbage collection.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255