Reputation: 54005
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?
Upvotes: 2
Views: 1478
Reputation: 75356
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
java -jar launchX.jar ...
java -jar launchY.jar ...
which saves you the -cp
stuff.
Upvotes: 0
Reputation: 52984
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.
Upvotes: 2
Reputation: 11087
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.
Upvotes: 2
Reputation: 23301
the first one is faster because you avoid copying a file. Other than that, they are exactly the same.
Upvotes: 4