2

我们在一个 ear 文件中部署了一些 war 文件。一些 war 文件有一个类,它以单例的形式缓存来自我们的 PLM 系统的静态数据。由于某些类需要几分钟才能加载,我们使用 web.xml 中的 load-on-startup 来提前加载它们。在我们尝试在生产服务器上重新部署应用程序之前,这一切都很好。(WebLogic 10.3) 我们从 PLM API 中得到一个关于已加载 dll 的异常。我们的 PLM 供应商已确认这是一个问题,并声明他们不支持使用启动时加载。这也是我们一直在重新部署应用程序的开发箱的一个大问题。我们大多数人,当我们不使用缓存的应用程序之一时,都会将它们注释掉。显然,我们不能为生产服务器这样做。

我们需要想办法解决这个问题...

一个建议是创建一个 servlet,我们可以在服务器启动后调用它来加载各种缓存。虽然这会起作用,但我正在寻找更清洁的东西。一旦服务器启动然后启动方法,是否有检测方法?

谢谢。

4

2 回答 2

1

What about using a servlet container lifecycle listener, such as ServletContextListener?

Example on how to use.

EDIT: Sorry, after re-reading your question I don't think this will work. You want something that will load only once per server life, not application life. The ServletContextListener's methods will be called each time the app is deployed, just like a load-on-startup servlet (which it seems you are using). My suggestion will do the exact same thing in a different way.

I would try Chris Nava's suggestion.

EDIT2: It looks like tomcat has some lifecycle listener(s) available to it also. It looks like documentation is sparse, but this potentially would allow you to do something on server startup specifically only once.

EDIT3: Yes, a tomcat lifecycle listener is the way to go. This link explains pretty well how to set one up. Should be fairly straight forward. If you ignore the part about adding the Transaction to tomcat, it goes over pretty thoroughly how to add a lifecycle listener.

于 2010-03-17T19:09:50.990 回答
1

我们在加载原生 DLL 的第三方 JDBC 驱动程序中遇到了类似的问题。重新部署应用程序时,驱动程序会崩溃,说 DLL 已加载。解决方案(如果可以这么说的话)是将驱动程序从部署移动到库中。这样,驱动程序对应用程序服务器来说是全局的,并且在重新部署应用程序时不需要重新加载。

于 2010-03-17T20:17:37.453 回答