views:

833

answers:

5

I am thinking of executing multiple instances of same java binary (a socket application) with different configuration files (As a command line parameter). Does the JVM correctly handles this situation? In other words If I haven't any common resources (Files that can be locked etc.) will this approach make any problems? If so what are things that I need to be careful.

+9  A: 

If you start multiple instances of java from the command line you get multiple running JVMs (one per instance).

If there are no shared resources you should have no problems at all.

Matthew Murdoch
A: 

No problem with that. Actually I find the inverse case a bit annoying - that there's no (easy) way to limit the number of launchable instances within the same computer.

Joonas Pulakka
+1  A: 

Did you actually try ? Why wouldnt this work ?

mP
+1  A: 

As Matthew pointed out earlier, as long as there are no shared resources we should see no problems.

Just to add a bit more, JVM is like a container that provides an execution environment for a java program and a JVM created each time we invoke java from the command line.

http://en.wikipedia.org/wiki/Java_Virtual_Machine

vprasanth
+1  A: 

If you have many instances then you may have a problem with excessive memory use and slow start up times. Much of the JRE is shared, but not everything and not in general application code and resources. Some JREs go to some extent to fix this, for instance recent versions of the IBM JRE 6 share compiled application code.

If all of your code is well written (no mutable static variables (including singletons), for instance), then it shouldn't be a problem to use a single process.

Tom Hawtin - tackline