About Question com.enthuware.ets.scwcd.v5.2.526 :

Moderator: admin

Post Reply
cyne

About Question com.enthuware.ets.scwcd.v5.2.526 :

Post by cyne »

Question:
Consider the following servlet code:

import javax.servlet.*;
public MyServlet extends GenericServlet implements Runnable
{
public void run()
{
//do something.
}
}

Which of the following statements are correct?

One of the answers to the question is: "Assuming that compilation errors are rectified (if any), the servlet container can run multiple threads simultaneously on the same instance of this servlet.".

Isn't it true however that creation of threads is not supported by the J2EE spec, and in fact is strongly discouraged? Wouldn't the answer therefore be: "Assuming that compilation errors are rectified (if any), the servlet container CANNOT run multiple threads simultaneously on the same instance of this servlet."?

admin
Site Admin
Posts: 10228
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.526 :

Post by admin »

No, the servlet container itself can create any number of threads for its needs. In fact, to increase performance, a servlet container usually processes multiple requests simultaneously by calling a servlet's service method using multiple threads.

This question is just trying to confuse you by making the servlet implement Runnable. It has no bearing on how the servlet container behaves.

Further, it is true that it is usually not a good idea for the application code to create threads in a container however, there can be situations when it might be required and a container does not prevent that from happening. But again, that is a different issue and is not relevant to this particular question.

HTH,
Paul
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests