并行运行 Servlet Web 应用程序的多个版本
我想并行运行多个基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
J2EE 应用程序使用单独的类加载器层次结构并且彼此隔离。引用 类加载器和 J2EE:
因此,是的,每个 Web 应用程序都有自己的
ClassLoader
(感谢上帝)。为什么难管理?为什么不灵活呢?您要并行运行多少个实例?实际上,你想解决什么问题?如果您描述真正的问题,您可能会得到更好的答案。那么,您能详细说明一下吗?
J2EE applications use separate hierarchy of ClassLoaders and are isolated from each others. Quoting Classloaders and J2EE:
So, yes, each webapp would have its own
ClassLoader
(thanks god).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?
除非您明确配置为如此,否则所有 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.
每个 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.