开发者

Multiple java processes from one jar

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:

  1. Launch each process off the exact same file:

    java -cp my_fat_deployment.jar net.example.MyMain15

  2. 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?


the first one is faster because you avoid copying a file. Other than that, they are exactly the same.


Unless you delete and generate .jar file with different content each time after java excection, You should go with first one

Second step is redundant, as jar name doesn't matter.


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.


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

  1. A Class-Path pointing to the large jar
  2. A Main-Class pointing to the launch class.

(plus whatever you need for record keeping).

You can then just do

java -jar launchX.jar ...
java -jar launchY.jar ...

which saves you the -cp stuff.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜