如何分叉JVM? [英] how to fork JVM?

查看:62
本文介绍了如何分叉JVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Java-类似C的叉子?

Possible Duplicate:
Java - C-Like Fork?

我想知道如何从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 process which replaces the current one and inherits some of its 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 available in most non-Unix OSes; e.g. U/win and Cygwin have struggled to emulate fork under Win32. In a language such as Java, the garbage collector & JIT compilers would tend to touch Vmem pages such that 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 all of the forked children. SysV shared memory will be detached.

大多数语言和许多库都拒绝 支持分叉.这包括(POSIX)线程API; 子执行之前不允许使用线程 (即成为生成物)!

Most languages and many libraries simply refuse to support 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 snapshots all local variables and state. That's also why there is no decent Unix shell for a non-Unix environment.

这篇关于如何分叉JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆