简体   繁体   English

从命令提示符多次运行Java程序

[英]Running a java program multiple times from command prompt

If i run a same multithreaded program from multiple command prompt, what would happen? 如果我从多个命令提示符运行相同的多线程程序,会发生什么? Each command prompt will run in diffrent jvm. 每个命令提示符将在不同的jvm中运行。 how the shared resources will access by threads in different jvm? 共享资源如何被不同jvm中的线程访问?

If i run a same multithreaded program from multiple command prompt, what would happen? 如果我从多个命令提示符运行相同的多线程程序,会发生什么?

there is seperate JVM for each program or application. 每个程序或应用程序都有单独的JVM。 (whether application is same or different) (申请是否相同)

how the shared resources will access by threads in different jvm? 共享资源如何被不同jvm中的线程访问?

As Same multithreaded application is executed by different JVM there is nothing(resources) to share by different JVM's. 由于同一多线程应用程序是由不同的JVM执行的,因此没有任何资源(资源)可以由不同的JVM共享。 As there are different java application are running same time(multiprocessing) shared resources of machine(memory , processor etc.) are handled by OS. 由于有不同的Java应用程序在同时运行(多处理),因此机器的共享资源(内存,处理器等)由OS处理。

Note:IF you are asking about shared resources in single multithreaded application please refer oracle docs 注意:如果您询问单个多线程应用程序中的共享资源,请参考oracle docs

Assuming the JVM isn't doing voodoo magic (knowing Oracle I can't be sure) each instance of Java would be running it's own thing and allocating it's own resources. 假设JVM并没有发挥伏都的魔力(我知道Oracle不确定),那么每个Java实例都将运行它自己的东西并分配它自己的资源。 As for how the host handles threading and resource distribution is a whole nother subject with tons of discussion and no good answer on how to do it (other than "Correctly") 至于主机如何处理线程和资源分配,这是一个充满话题性的主题,讨论的内容很多,没有很好的答案(“正确”除外)

To share resources among different JVM you need an external player, a Redis DB or similar, however if your program is multithread, why do you need to run different process ? 要在不同的JVM之间共享资源,您需要一个外部播放器,一个Redis DB或类似的程序,但是,如果您的程序是多线程的,为什么需要运行不同的进程? Why don't you run it just one time ? 您为什么不只运行一次?

Each command prompt will run in diffrent jvm - Yes. 每个命令提示符将在不同的jvm中运行-是的。 Among different jvms Resource sharing will be decided by operating system. 在不同的jvm之间,资源共享将由操作系统决定。

If two instances of JVM run the same multi threaded application, you cannot do resource sharing. 如果JVM的两个实例运行相同的多线程应用程序,则无法进行资源共享。 Remember, resource sharing and concurrency control is between multiple threads running a single JVM process. 请记住,资源共享和并发控制是在运行单个JVM进程的多个线程之间进行的。 Two such JVM processes, running the same application code, cannot do any concurrency control and resource sharing. 两个运行相同应用程序代码的JVM进程无法进行任何并发控制和资源共享。 For example, if the first JVM process opens a file, the second JVM process will not be able to access that file. 例如,如果第一个JVM进程打开了一个文件,则第二个JVM进程将无法访问该文件。 I hope this answers your question. 我希望这回答了你的问题。 If there is something specific which you are trying, then describe that, so that, we can offer you suggestions. 如果您要尝试某些特定的内容,请对其进行描述,以便我们为您提供建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM