控制servlet何时死亡

时间:2021-07-11 20:10:34

I have some configuration stored in the servlet context, sharing among servlets. The current approach is to load the config into a single copy of static hashmap shared by the servlets when the init() method of any servlet is called. But the problem is the servlets just won't die, so the configuration just won't reset even if I changed the configuration in the servlet context. Because the servlet never call init() again, they will not reload the configuration into the hashmap.

我有一些配置存储在servlet上下文中,在servlet之间共享。当前的方法是在调用任何servlet的init()方法时将配置加载到servlet共享的静态hashmap的单个副本中。但问题是servlet不会死,所以即使我更改了servlet上下文中的配置,配置也不会重置。因为servlet再也不会调用init(),所以它们不会将配置重新加载到hashmap中。

I am using websphere 7, is there any place I can configure when does a servlet die, and a new servlet is born?

我正在使用websphere 7,有什么地方我可以配置什么时候servlet死了,一个新的servlet诞生了?

I think it is too clumsy to reload the configuration from the servlet context when there is a new request.

我认为当有新请求时从servlet上下文重新加载配置太笨拙了。


Edit: I have a scheduler which will create a new thread to check for a specific data file, if the data file was new, it will create a hashmap(with content of the data file) as an attribute in the servlet context.

编辑:我有一个调度程序,它将创建一个新线程来检查特定的数据文件,如果数据文件是新的,它将创建一个hashmap(包含数据文件的内容)作为servlet上下文中的属性。

Now the servlets will check for the servlet context for the hashmap and copy it to a static hashmap for shared use among servlets when they are just created and call init(). But the problem is that the servlet won't die during the execution, it just make the scheduled action not working.

现在,servlet将检查hashmap的servlet上下文,并将其复制到静态hashmap,以便在servlet刚刚创建时共享使用并调用init()。但问题是servlet在执行过程中不会死,它只会使计划的操作无效。

2 个解决方案

#1


0  

I am using websphere 7, is there any place I can configure when does a servlet die, and a new servlet is born?

我正在使用websphere 7,有什么地方我可以配置什么时候servlet死了,一个新的servlet诞生了?

No.

Edit: I have a scheduler which will create a new thread to check for a specific data file, if the data file was new, it will create a hashmap(with content of the data file) as an attribute in the servlet context.

编辑:我有一个调度程序,它将创建一个新线程来检查特定的数据文件,如果数据文件是新的,它将创建一个hashmap(包含数据文件的内容)作为servlet上下文中的属性。

Now the servlets will check for the servlet context for the hashmap and copy it to a static hashmap for shared use among servlets when they are just created and call init(). But the problem is that the servlet won't die during the execution, it just make the scheduled action not working.

现在,servlet将检查hashmap的servlet上下文,并将其复制到静态hashmap,以便在servlet刚刚创建时共享使用并调用init()。但问题是servlet在执行过程中不会死,它只会使计划的操作无效。

Refactor the settings into a separate data object (rather than a HashMap or servlet instance fields) to be shared by servlet instances. Change the scheduler/alarm to update the shared data object directly.

将设置重构为要由servlet实例共享的单独数据对象(而不是HashMap或servlet实例字段)。更改调度程序/警报以直接更新共享数据对象。

#2


0  

Why not store this data in JNDI, where the servlets can get it whenever they need it? That way, you have complete control of the data; the servlet lifecycle would no longer matter.

为什么不将这些数据存储在JNDI中,servlet可以在需要时获取它?这样,您就可以完全控制数据; servlet生命周期将不再重要。

#1


0  

I am using websphere 7, is there any place I can configure when does a servlet die, and a new servlet is born?

我正在使用websphere 7,有什么地方我可以配置什么时候servlet死了,一个新的servlet诞生了?

No.

Edit: I have a scheduler which will create a new thread to check for a specific data file, if the data file was new, it will create a hashmap(with content of the data file) as an attribute in the servlet context.

编辑:我有一个调度程序,它将创建一个新线程来检查特定的数据文件,如果数据文件是新的,它将创建一个hashmap(包含数据文件的内容)作为servlet上下文中的属性。

Now the servlets will check for the servlet context for the hashmap and copy it to a static hashmap for shared use among servlets when they are just created and call init(). But the problem is that the servlet won't die during the execution, it just make the scheduled action not working.

现在,servlet将检查hashmap的servlet上下文,并将其复制到静态hashmap,以便在servlet刚刚创建时共享使用并调用init()。但问题是servlet在执行过程中不会死,它只会使计划的操作无效。

Refactor the settings into a separate data object (rather than a HashMap or servlet instance fields) to be shared by servlet instances. Change the scheduler/alarm to update the shared data object directly.

将设置重构为要由servlet实例共享的单独数据对象(而不是HashMap或servlet实例字段)。更改调度程序/警报以直接更新共享数据对象。

#2


0  

Why not store this data in JNDI, where the servlets can get it whenever they need it? That way, you have complete control of the data; the servlet lifecycle would no longer matter.

为什么不将这些数据存储在JNDI中,servlet可以在需要时获取它?这样,您就可以完全控制数据; servlet生命周期将不再重要。