有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java请求servlet时会发生什么?

我知道当一个servlet被请求时,init()、service()和destroy()会被连续调用。当请求servlet时,会为每个请求创建一个线程。那么,对于每个线程,整个servlet上下文都会被初始化,就像所有上下文参数和init参数都被重新设置一样


共 (1) 个答案

  1. # 1 楼答案

    I know that when a servlet is requested, the init(), service() and destroy() are called consecutively.

    不,您不需要。servlet在其生命周期中与容器一起初始化和销毁一次。不是按要求

    When a servlet is requested, a thread is created for every request.

    不,不是。线程通常是从线程池中分配的

    So, for each thread the whole servlet context is initialized like all the context-params and init-param are set again?

    不,见上图