并行运行 Servlet Web 应用程序的多个版本

发布于 2024-08-17 13:44:41 字数 280 浏览 6 评论 0原文

我想并行运行多个基于 Java Servlet 的 Web 应用程序的多个版本(如 myapp2.1、myapp2.2 ...)。

一种可能性是将每个版本部署到单独的 servlet 上下文(应该有自己的类加载器?!)。但我认为这将很难管理并且不灵活,因为应用程序是一个相当大的块。如果应用程序应包含两个不同版本的服务怎么办?也许这不是一个好主意......

环境将是 GlassFish >= 3.0。

并行运行 servlet 应用程序的多个版本的更好方法是什么? OSGI 可以帮忙吗?

I want to run multiple versions (like myapp2.1, myapp2.2 ...) of several Java Servlet based web applications parallel.

One possibility could be to deploy each version to a separate servlet context (which should have its own class loader?!). But I think it will be hard to manage and won't be flexible, since an application is a quite large block. What if an application should contain a service in two different versions? Maybe that is not a good idea ...

The environment will be GlassFish >= 3.0.

What is a better way to run multiple versions of a servlet application parallel? Could OSGI help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生死何惧 2024-08-24 13:44:42

一种可能是将每个版本部署到单独的 servlet 上下文(它应该有自己的类加载器?!)。

J2EE 应用程序使用单独的类加载器层次结构并且彼此隔离。引用 类加载器和 J2EE

J2EE 类加载器层次结构

J2EE 指定层次结构
需要类加载器来实现
应用程序之间的隔离,但是
让供应商来定义
精确的结构。但要遵守
根据 J2EE 规范,大多数
供应商有每个类加载器
J2EE 应用程序组件
取决于它的位置。更远,
这些类加载器有一个层次结构
他们之间,即他们有一个
亲子关系。图21.5
显示了示例层次结构
类加载器。请注意,每个
应用服务器的类加载器
层次结构可能略有不同。
应用服务器供应商有时
倾向于治疗其中两个或多个
类加载器合而为一。例如,一个
某些应用程序服务器可能会处理
应用程序类加载器和 EJB
类加载器是相同的。但是
层次结构背后的一般概念
保持不变。

J2EE 应用程序服务器中的示例类加载器层次结构 http://www.objectsource。 com/j2eechapters/Ch21-ClassLoaders_and_J2EE_files/image016.jpg

图 21.5 J2EE 应用程序服务器中的示例类加载器层次结构。

因此,是的,每个 Web 应用程序都有自己的 ClassLoader(感谢上帝)。

但我认为这将很难管理并且不灵活。

为什么难管理?为什么不灵活呢?您要并行运行多少个实例?实际上,你想解决什么问题?如果您描述真正的问题,您可能会得到更好的答案。那么,您能详细说明一下吗?

One possibility could be to deploy each version to a separate servlet context (which should have its own class loader?!).

J2EE applications use separate hierarchy of ClassLoaders and are isolated from each others. Quoting Classloaders and J2EE:

J2EE classloader hierarchy

J2EE specifies that a hierarchy of
classloaders is needed to achieve the
isolation between applications, but
leaves it to the vendors to define the
exact structure. However to comply
with the J2EE specification, most
vendors have classloaders for each of
the J2EE application components
depending on its location. Further,
these classloaders have a hierarchy
among themselves, i.e. they have a
parent-child relationship. Figure 21.5
shows a sample hierarchy of
classloaders. Note that each
application server’s classloader
hierarchy might slightly differ.
Application server vendors sometimes
tend to treat two or more of these
classloaders as one. For instance, a
certain application server might treat
Application classloader and EJB
classloader to be the same. But the
general concepts behind the hierarchy
remain the same.

Sample Classloader Hierarchy in J2EE Application Servers http://www.objectsource.com/j2eechapters/Ch21-ClassLoaders_and_J2EE_files/image016.jpg

Figure 21.5 Sample Classloader Hierarchy in J2EE Application Servers.

So, yes, each webapp would have its own ClassLoader (thanks god).

But I think it will be hard to manage and won't be flexible.

Why hard to manage? Why not flexible? How many instances are you going to run in parallel? Actually, what problem are you trying to solve? You may get better answer if you describe the real problem. So, can you elaborate a bit?

沫离伤花 2024-08-24 13:44:42

除非您明确配置为如此,否则所有 servlet 都是多线程的,并且可以一次调用多次。

那么,您是否想要多个具有相同代码但名称不同的 Web 应用程序,或者同一 Web 应用程序中具有不同配置的多个 Servlet?请用场景编辑您的问题。


编辑:您现在已经编辑了问题。

您只需将部署的 war 文件命名为 application20091230、application20091231、application20100101,然后让 Glassfish 将其分配给相应的 URL。如果日期不够精细,则可以使用日期时间或内部版本号。

这就是我们在单个内部测试服务器中拥有多个版本所做的事情。

Unless you explicitly configure it to be so, all servlets are multi-threaded and can be invoked several times at once.

So, do you want several web applications with the same code but different names or several servlets inside the same web applciation with different configurations? Please edit your question with a scenario.


EDIT: You have now edited the question.

You can simply just name the war file you deploy like application20091230, application20091231, application20100101 and let Glassfish assign it to the corresponding URL. If date is not granular enough, then either a datetime or a buildnumber.

That's what we do for having several versions in a single internal test server.

对不⑦ 2024-08-24 13:44:41

每个 Web 应用程序都将使用自己的 ClassLoader 进行加载(至少是我所知道的任何容器;我无法想象为什么容器不会这样做)。所以,它应该可以工作。您的课程的不同版本不会互相干扰。

确保容器自己的类加载器中没有包含任何类 - 例如,将 .jar 放入 Tomcat 目录中的 lib/ 中(不确定 Glassfish 的等效项)。这将由所有 Web 应用程序共享,并将覆盖 Web 应用程序中的任何内容。

Each web application will be loaded using its own ClassLoader (at least any container I know of; I can't imagine why a container would not do this). So, it should just work. Different versions of your classes will not interfere with one another.

Make sure you do not include any of your classes in the container's own ClassLoader -- for example by putting a .jar in lib/ in Tomcat's directory (not sure of the equivalent for Glassfish). That would be shared by all web applications, and would override whatever is in the web app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文