Difficulty: Easy
Correct Answer: By one of Tomcat's threads
Explanation:
Introduction / Context:
JSP is a server-side view technology that compiles to a servlet. In servlet containers like Apache Tomcat, requests are handled within a multithreaded Java process. Understanding this execution model helps with performance tuning, thread safety, and resource management.
Given Data / Assumptions:
Concept / Approach:
Tomcat translates a JSP into Java source for a servlet, compiles it to bytecode, loads it, and executes it within the container. Each incoming request is processed by a thread from Tomcat’s thread pool calling the servlet’s service method. This is not CGI (external process per request) nor an independent OS process per JSP; it is a method invocation within the JVM managed by Tomcat’s threading model.
Step-by-Step Solution:
Verification / Alternative check:
Observe Tomcat work directories where generated servlet code is stored; thread dumps show request-handling threads executing servlet methods, confirming the thread-based model.
Why Other Options Are Wrong:
CGI: spawns external processes, not used by Tomcat for JSPs.
Independent process: Tomcat does not spawn a process per JSP request.
None of the above: incorrect because threads are the correct mechanism.
Common Pitfalls:
Writing non-thread-safe JSP/servlet code (for example, mutable static fields); assuming per-request isolation like CGI when in fact state can be shared within the JVM process.
Final Answer:
By one of Tomcat's threads
Discussion & Comments