一个 jar 中的多个 java 进程
想象一个 5 MB 的 jar 文件,其中包含许多“主”类,每个类都作为自己的进程使用 java -cp my_fat_deployment.jar net.example.MyMain15
之类的内容启动。有些进程会持续运行数天,而另一些则持续运行几分钟或几秒钟。一次可以有 5 到 20 个启动并运行。
我试图比较两种执行方法:
从完全相同的文件启动每个进程:
java -cp my_fat_deployment.jar net.example.MyMain15
从副本启动:
cp my_fat_deployment.jar my_copy_15.jar
java -cp my_copy_15.jar net.example.MyMain15
我正在谈论 Linux 机器上的 Sun 的 Java,以防万一。
每种方法都有哪些优缺点?第一个有任何稳定性或安全问题吗?哪个更快,为什么?
Imagine a 5 MB jar file that contains many "main" classes, each of which is started as its own process with something like java -cp my_fat_deployment.jar net.example.MyMain15
. Some processes keep running for days, others for minutes or seconds. There can be between 5 and 20 of them up and running at a time.
I'm trying to compare two ways of executing it:
Launch each process off the exact same file:
java -cp my_fat_deployment.jar net.example.MyMain15
Launch from a copy:
cp my_fat_deployment.jar my_copy_15.jar
java -cp my_copy_15.jar net.example.MyMain15
I'm talking about Java from Sun on a Linux box, in case it matters.
What pros and cons does each approach have? Does the first one have any stability or security issues? Which is faster and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个更快,因为您避免了复制文件。除此之外,它们完全相同。
the first one is faster because you avoid copying a file. Other than that, they are exactly the same.
除非每次在java异常后删除并生成具有不同内容的
.jar文件
,否则您应该选择第一个第二步是多余的,因为jar名称并不重要。
Unless you delete and generate
.jar file
with different content each time after java excection, You should go with first oneSecond step is redundant, as jar name doesn't matter.
两种方式是相同的。它们之间没有区别,只是制作副本会占用更多磁盘空间。
当然,如果您以后想要独立升级每个进程,则需要使用单独的 JAR。
Both ways are identical. There is no difference between them, except that making a copy takes up more disk space.
Of course, if you later want to upgrade each process independently, you will need to use separate JARs.
在一个大 jar 中拥有多个启动点的最简单方法是为每个启动点提供一个额外的 jar,其中只包含一个清单,其中包含
(加上保存记录所需的任何内容)。
然后你就可以这样做
,这样可以节省
-cp
的东西。The easiest way to have multiple launch points in a large jar, is to have an extra jar for each launch point which just contain a manifest with
(plus whatever you need for record keeping).
You can then just do
which saves you the
-cp
stuff.