问题描述
我想知道如何从JDK派生子JVM,甚至有可能这样做?
I wanted to know how is it possible to fork a child JVM from a JDK or even is it possible to do so?
诸如hadoop之类的某些框架为特定任务派生了一个子JVM,因此请对此主题有所了解.
Some frameworks like hadoop fork a child JVM for specific tasks thus Please throw some light on the subject.
谢谢!
推荐答案
Fork通常与spawn混淆.Spawn是fork + exec(这意味着启动一个进程它取代了当前的,并继承了一些它的外部资源,例如开放式套接字).
Fork is commonly confused with spawn.Spawn is fork + exec (which means start a processwhich replaces the current one and inherits some ofits external resources, such as open sockets).
可以在Java中使用Spawn(通过System.exec等).
Spawn is available in Java (via System.exec and the like).
叉不是用Java编写的,因为它会带来极大的问题.
Fork is not in Java, because it would be extremely problematic.
Fork需要克隆地址空间.没有有效支持此操作的内核支持在大多数非Unix操作系统中;例如U/win和Cygwin都在挣扎在Win32下模拟fork.在Java之类的语言中,垃圾收集器& JIT编译器倾向于接触Vmem页面,例如分叉后该空间将不会长时间保持共享状态.
Fork requires cloning of the address space.The kernel support to do this efficiently is not availablein most non-Unix OSes; e.g. U/win and Cygwin have struggledto emulate fork under Win32.In a language such as Java, the garbage collector& JIT compilers would tend to touch Vmem pages suchthat the space would not long remain shared after fork.
克隆有很多副作用.例如,输入或输出缓冲区将在所有分叉的孩子. SysV共享内存将被分离.
Cloning has many side effects.E.g., input or outputs buffers will be processed in allof the forked children. SysV shared memory will be detached.
大多数语言和许多库都拒绝支持分叉.这包括(POSIX)线程API;子执行之前不允许使用线程(即成为生成物)!
Most languages and many libraries simply refuse tosupport forking. This includes the (POSIX) threading API ;The child is not allowed to use threads until it execs(i.e., becomes a spawn) !
Perl之所以使用fork是因为它的内部非常接近C/Unix,而且它的多线程功能非常糟糕.
Perl uses fork because its internals are extremely close to C/Unix,and its multithreading is abysmal.
Unix shell是按设计使用fork的,这就是快照的方式所有局部变量和状态.这就是为什么没有在非Unix环境中使用合适的Unix Shell.
Unix shell uses fork by design, which is how it snapshotsall local variables and state. That's also why there is nodecent Unix shell for a non-Unix environment.
这篇关于如何分叉JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!