我可以执行Java类文件的多个实例吗?

时间:2022-11-25 00:23:46

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.

我正在考虑使用不同的配置文件(作为命令行参数)执行相同java二进制文件(套接字应用程序)的多个实例。 JVM是否正确处理了这种情况?换句话说,如果我没有任何公共资源(可以锁定的文件等),这种方法会产生任何问题吗?如果是这样的话,我需要小心的是什么。

4 个解决方案

#1


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

如果从命令行启动多个java实例,则会获得多个正在运行的JVM(每个实例一个)。

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

如果没有共享资源,您应该没有任何问题。

#2


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

正如Matthew先前所指出的那样,只要没有共享资源,我们就不应该看到任何问题。

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.

只是为了增加一点,JVM就像一个容器,为每次从命令行调用java时创建的java程序和JVM提供执行环境。

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

#3


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.

如果您有许多实例,那么您可能会遇到内存使用过多和启动时间慢的问题。大部分JRE是共享的,但不是所有内容,而不是一般的应用程序代码和资源。一些JRE在某种程度上解决了这个问题,例如最近版本的IBM JRE 6共享编译的应用程序代码。

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.

如果您的所有代码都写得很好(例如,没有可变的静态变量(包括单例)),那么使用单个进程应该不是问题。

#4


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.

没问题。实际上我发现相反情况有点烦人 - 没有(简单)方法来限制同一台计算机中可启动实例的数量。

#1


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

如果从命令行启动多个java实例,则会获得多个正在运行的JVM(每个实例一个)。

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

如果没有共享资源,您应该没有任何问题。

#2


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

正如Matthew先前所指出的那样,只要没有共享资源,我们就不应该看到任何问题。

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.

只是为了增加一点,JVM就像一个容器,为每次从命令行调用java时创建的java程序和JVM提供执行环境。

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

#3


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.

如果您有许多实例,那么您可能会遇到内存使用过多和启动时间慢的问题。大部分JRE是共享的,但不是所有内容,而不是一般的应用程序代码和资源。一些JRE在某种程度上解决了这个问题,例如最近版本的IBM JRE 6共享编译的应用程序代码。

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.

如果您的所有代码都写得很好(例如,没有可变的静态变量(包括单例)),那么使用单个进程应该不是问题。

#4


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.

没问题。实际上我发现相反情况有点烦人 - 没有(简单)方法来限制同一台计算机中可启动实例的数量。